#32654 [Opn->Bgs]: Magic __parent property (or method)
| From: | helly@php.net | Date: | Sun, 10 Apr 2005 10:22:27 +0000 |
| Subject: | #32654 [Opn->Bgs]: Magic __parent property (or method) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-76586@lists.php.net to get a copy of this message | ||
ID: 32654
Updated by: helly@php.net
Reported By: bart at mediawave dot nl
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
-Operating System: Any
+Operating System: *
-PHP Version: 5CVS-2005-04-10 (dev)
+PHP Version: *
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
There is no such thing as a parent object. Use 'parent::'<method>'()'
to access methods of the parent.
Previous Comments:
------------------------------------------------------------------------
[2005-04-10 10:14:44] bart at mediawave dot nl
Description:
------------
When writing code with complex object structures I often need a
reference to the parent object. Let's say we have an object "parent"
that has a property which is an object "child":
class parentClass {
var $child;
var $dummyVar;
function __construct() {
$this->child = new childClass($this);
$this->dummyVar = 'hello';
}
}
class childClass {
var $parent;
function __construct($parent) {
$this->parent = $parent;
echo $this->parent->dummyVar;
}
}
$example = new parentClass;
// prints: hello
I very often need to create my code like this because I very often need
to be able to have a reference to the parent object of an object.
Shouldn't PHP have such a reference by default? There could always be a
Magic reference like:
$myParent = $this->__parent;
Or maybe a Magic method:
$myParent = $this->__parent();
This would then always return the parent object or eventually reach the
main script scope.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32654&edit=1