I would like to have a function in my class that has a default parameter so that one can omit the argument if required. I want the default to be a variable stored in my class;
Hi why is this showing error messages in Aptana?
class property{
private $id;
function load_data($id = $this->id){
//...blah blah blah
}
}
Should I instead use
class property{
static $id;
function load_data($id = self::id){
//...blah blah blah
}
}
?
Thanks for the help
I'm pretty sure you can't do what you're looking for. Instead you should simply check to see if the argument has a value, and if it doesn't, assign the default value which is the object property.
class property{
private $id;
function load_data($id = null){
$id = (is_null($id)) ? $this->id : $id;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With