note 30710 added to keyword.parent

From: Date: Wed, 26 Mar 2003 14:09:43 +0000
Subject: note 30710 added to keyword.parent
Groups: php.notes 
Request: Send a blank email to php-notes+get-45854@lists.php.net to get a copy of this message
I've been scouring through the comments but haven't been able to find an example of how to use variable overriding. The manual hints that it is possible, but there aren't any examples. See the code for what I want to do: class A { var $x; function A() { $this->x = 32; } function joke() { print "A::joke" . A::x . "<br>\n"; # SYNTAX ERROR!! } } class B extends A { var $x; function B() { parent::A(); $this->x = 44; } function joke() { parent::joke(); print "B::joke " . $this->x . "<br>\n"; } } I want the following output when I call B::joke: A::joke 32 B::joke 44 what do I get if I replace the A::x with $this->x? A::joke 44 B::joke 44 How do I set the variable $x in the base class? Or, how do I get $this to point to the part of the class that is owned by class A? I've tried the following (quite invalid) syntaxes: A::x A::$x ${A::x} A::{$this->x} It'd be nice to have a concrete example of how to access (read and write) parent variable members, or explicitly say that it is not possible to do that. -- http://www.php.net/manual/en/keyword.parent.php http://master.php.net/manage/user-notes.php?action=edit+30710 http://master.php.net/manage/user-notes.php?action=delete+30710 http://master.php.net/manage/user-notes.php?action=reject+30710

« previous php.notes (#45854) next »