class - in php why does isn't work -


class grandclass {     public $data;     public function __construct() {         $this->somemethodintheparentclass();     }     public function somemethodintheparentclass() {         $this->$data = 123456;     } }  class myparent extends grandclass{     public function __construct() {         parent::__construct();     } }  class child extends myparent {     // public $data;     public function __construct() {         parent::__construct();     }     public function getdata() {         return $this->data;      } }  $a = new child(); var_dump($a->getdata()); 

php notice: undefined variable: data in d:\test.php on line 7

php fatal error: cannot access empty property in d:\test.php on line 7

update function somemethodintheparentclass below using $this->data = 123456;

 public function somemethodintheparentclass() {         $this->data = 123456;     } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -