我是OOP的新手,所以這可能是一個非常天真的問題;但每當我嘗試使用$this->var
語法將類局部變量傳遞到該類中的函數時,它會在我的IDE(NetBeans)中標記語法錯誤。將本地屬性/變量傳遞給該類中的函數/方法?
我試過把它套在括號裏({$this->var}
和$this->{var}
),但都沒有效果。
這裏是我的代碼:
class password_class {
public $stretch = 1;
public $salt = 'DEFINE_SALT';
public $algo = 'sha256';
function create_salt() {
$this->salt = md5(rand()).uniqid();
}
function hash_pass($pass, $this->algo, $this->salt, $this->stretch) {
}
}
我真的不打算使用這個密碼安全措施;它更多的是測試類變量/函數的使用(這將是我第一次創建和調用我自己的類)。
任何幫助將不勝感激!
你不需要'$這個 - > algo,$ this-> salt,$ this-> stretch',你可以在*函數中使用它們。 –
您不需要將本地變量傳遞給本地方法,您可以在方法中使用它們。 – favoretti