note 71096 rejected from language.oop5.basic by bobby
| From: | bobby@php.net | Date: | Mon, 13 Nov 2006 17:01:50 +0000 |
| Subject: | note 71096 rejected from language.oop5.basic by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-119688@lists.php.net to get a copy of this message | ||
Note Submitter: keuleu at hotmail dot com
----
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
?>