note 71096 added to language.oop5.basic

From: Date: Sun, 12 Nov 2006 05:39:53 +0000
Subject: note 71096 added to language.oop5.basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-119619@lists.php.net to get a copy of this message
The manual says somewhere above: "It is possible to access the overrided method or members by referencing them with parent::" I don't exactly know what it means by members, but if I'm not mistaking member is another term to designate variables or objects defined as properties of a class. I just would like to point out that although it is clearly possible to access parent *methods* like described (numerous examples on the internet), I have tried unsuccessfully to reference, overrided or not, parent *members* (protected or public) with the 'parent' keyword, nor was I able to find a well documented explanation on how to do so. Nowhere in the manual does it specifically tell you how to explicitly access parent variables. The only way I know is to use the traditional $this (which is not an explicit parent reference). The following example to illustrate: <?php class A{ public $x; function __construct(){ $this->x=33; } } class B extends A { function __construct(){ parent::__construct(); // works fine echo parent::$x; //this would have been explicit but it doesn't work echo $this->x; //implicitly accessing the same parent member will work fine } } $b = new B(); # Fatal error: Access to undeclared static property: A::$x on line 15 ?> ---- Server IP: 216.235.15.211 Probable Submitter: 216.99.40.153 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php Edit -- https://master.php.net/note/edit/71096 Del: integrated -- https://master.php.net/note/delete/71096/integrated Del: useless -- https://master.php.net/note/delete/71096/useless Del: bad code -- https://master.php.net/note/delete/71096/bad+code Del: spam -- https://master.php.net/note/delete/71096/spam Del: non-english -- https://master.php.net/note/delete/71096/non-english Del: in docs -- https://master.php.net/note/delete/71096/in+docs Del: other reasons-- https://master.php.net/note/delete/71096 Reject -- https://master.php.net/note/reject/71096 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119619) next »