This may be a very dumb question, but how can I pass a parameter as a local variable in a PHP class.
e.g (this does not work, but represents what I want)
public function sql($this->sql_statement){
// do something
}
I would like the passed parameter to become the ‘$this->sql_statement’ variable
Obviously, I could just do this, but I want to know if there is a better way:
public function sql($statement){
$this->sql_statement = $statement;
// do something
}
To the best of my knowledge, there is no better way. As your method may be called from outside the class, you essentially need to treat it as a standard setter method: set the member variable to the value of the passed parameter, just like in your second code.