#46654 [NEW]: circular reference suggestion

From: Date: Sun, 23 Nov 2008 15:44:42 +0000
Subject: #46654 [NEW]: circular reference suggestion
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-131228@lists.php.net to get a copy of this message
From: luka8088 at gmail dot com Operating system: PHP version: 5.3.0alpha2 PHP Bug Type: Feature/Change Request Bug description: circular reference suggestion Description: ------------ I have a suggestion for circular reference problem, already mentioned in report 33595 ... I realize that it is already fix in cvs with David Wang's patch, but maybe this would also be good to have ? Reproduce code: --------------- for example: class foo { function __construct () { $this->bar = new bar($this); } function __refcount ($count) { if ($count <= 1) unset($this->bar); } } class bar { function __construct ($foo = null) { $this->foo = $foo; } } $object = new foo(); unset($object); // $object->__refcount(1); // one reference left Expected result: ---------------- now, this would create a circular reference when creating foo, and I suggest that when a reference to an object is removed or added, and refcount changes, a __refcount method is called, that way, in some cases when object knows how many circular references it has, can unset them and free the memory... in this example, foo knows that it has exactly 1 reference from bar, and if count is greater then 1, it is still needed... I know that with this, David Wang's patch may still be needed for objects that don't know the exact refcount, but this may have some good effect on performance ? rather then calculating circular references ? -- Edit bug report at http://bugs.php.net/?id=46654&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46654&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46654&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46654&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46654&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46654&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=46654&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46654&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46654&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46654&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46654&r=support Expected behavior: http://bugs.php.net/fix.php?id=46654&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46654&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46654&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46654&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46654&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46654&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46654&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46654&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46654&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46654&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46654&r=mysqlcfg

« previous php.bugs (#131228) next »