I was trying to write a class in such simple way
class piklu
{
private $x=5;
public function display()
{
echo $this->$x;
}
}
but when after creating object of this class I'm calling the function display it is displaying an error unkown variable $x. Can any body suggest me what exactly I have to do to declare a private member variable in php.
Your echo statement is incorrect, which is your problem. It should be:
public function display()
{
echo $this->x;
}
Note that there's only one $
here: right before the keyword this
. You mistakenly had two dollar signs.
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