#32654 [NEW]: Magic __parent property (or method)
| From: | bart at mediawave dot nl | Date: | Sun, 10 Apr 2005 08:14:45 +0000 |
| Subject: | #32654 [NEW]: Magic __parent property (or method) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-76585@lists.php.net to get a copy of this message | ||
From: bart at mediawave dot nl
Operating system: Any
PHP version: 5CVS-2005-04-10 (dev)
PHP Bug Type: Feature/Change Request
Bug description: Magic __parent property (or method)
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 bug report at http://bugs.php.net/?id=32654&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32654&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32654&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32654&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=32654&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=32654&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=32654&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=32654&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=32654&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=32654&r=support
Expected behavior: http://bugs.php.net/fix.php?id=32654&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=32654&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=32654&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=32654&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32654&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=32654&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=32654&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=32654&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=32654&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=32654&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=32654&r=mysqlcfg