note 84873 added to keyword.parent
| From: | nateat8 at osu1 dot php dot net | Date: | Sun, 03 Aug 2008 04:06:58 +0000 |
| Subject: | note 84873 added to keyword.parent | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143084@lists.php.net to get a copy of this message | ||
To simulate traditional C# like parent access, child classes can be defined in the parent's
constructor and linked via explict definition. ($this->b->par = $this;)
========================================
class A {
var $foo;
var $b;
function A(){
$this->foo = "foo!";
$this->b = new B;
$this->b->par = $this;
}
function bar(){
print("bar!");
}
};
class B {
var $par;
function B(){
}
function bar(){
print( $this->par->foo );
$this->par->bar();
}
};
$test = new A;
$test->b->bar();
===================================
This returns:
foo!bar!
demonstrating both variable and function access via the parent.
----
Server IP: 209.41.74.194
Probable Submitter: 68.49.231.195
----
Manual Page -- http://www.php.net/manual/en/keyword.parent.php
Edit -- https://master.php.net/note/edit/84873
Del: integrated -- https://master.php.net/note/delete/84873/integrated
Del: useless -- https://master.php.net/note/delete/84873/useless
Del: bad code -- https://master.php.net/note/delete/84873/bad+code
Del: spam -- https://master.php.net/note/delete/84873/spam
Del: non-english -- https://master.php.net/note/delete/84873/non-english
Del: in docs -- https://master.php.net/note/delete/84873/in+docs
Del: other reasons-- https://master.php.net/note/delete/84873
Reject -- https://master.php.net/note/reject/84873
Search -- https://master.php.net/manage/user-notes.php