note 117202 added to keyword.parent

From: Date: Fri, 01 May 2015 10:42:17 +0000
Subject: note 117202 added to keyword.parent
Groups: php.notes 
Request: Send a blank email to php-notes+get-202407@lists.php.net to get a copy of this message
We can't use parent:: keyword to access property of the parent class like methods as variables are not overridable as method does Consider the following code <?php class Fish { public $common_name = 'Name'; } class Trout extends Fish { public function getInfo() { return parent::$common_name; } } $brook_trout = new Trout(); echo $brook_trout->getInfo(); ?> this will cause following error Fatal error: Access to undeclared static property: Fish::$common_name Simply use $this keyword to access both own and parent's variable ---- Server IP: 72.52.91.14 Probable Submitter: 122.168.99.1 ---- Manual Page -- http://php.net/manual/en/keyword.parent.php Edit -- https://master.php.net/note/edit/117202 Del: integrated -- https://master.php.net/note/delete/117202/integrated Del: useless -- https://master.php.net/note/delete/117202/useless Del: bad code -- https://master.php.net/note/delete/117202/bad+code Del: spam -- https://master.php.net/note/delete/117202/spam Del: non-english -- https://master.php.net/note/delete/117202/non-english Del: in docs -- https://master.php.net/note/delete/117202/in+docs Del: other reasons-- https://master.php.net/note/delete/117202 Reject -- https://master.php.net/note/reject/117202 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202407) next »