I’m new to OOP, so this could be an extremely naive question; but whenever I attempt to pass a class local variable into a function within that class using the $this->var syntax, it flags up a syntax error in my IDE (NetBeans).
I’ve tried encasing it in parentheses (both {$this->var} and $this->{var}) but neither seem to work.
Here’s my code:
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) {
}
}
I don’t actually plan on using this for password security measures; it was more of a test to see the use of class variables/functions (this will be my first time creating and calling my own class).
Any help would be greatly appreciated!
In OOP if you use instance attribute, you don’t need to pass them as params. Infact, if you want to use
$this->algoand so on you can simply do:Moreover if you need the params you can do this: