|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-09-27 22:02 UTC] tony2001@php.net
[2005-10-05 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
Description: ------------ I found an incompatibility between the __destruct() fonction and the references. When assigning your object (which countains __destruct() ) using references ($myObject =& new TheObject();) for the second time (or more), the second object will be deleted just like the first and your variable will countain only the NULL value. Look at the code... Excuse me for my english, but I'm french, and I hope you'll understand ;-) Reproduce code: --------------- class TheObject { function __construct() { echo "__construct()...\n"; } function __destruct() { echo "__destruct()...\n"; } } echo "<pre>"; $myObject =& new TheObject(); var_dump($myObject); // => a TheObject object $myObject =& new TheObject(); var_dump($myObject); // => NULL !!!! echo "</pre>"; Expected result: ---------------- I'd like to see this output : __construct()... object(TheObject)#1 (0) { } __destruct()... __construct()... object(TheObject)#2 (0) { } __destruct()... or this one will work too : __construct()... object(TheObject)#1 (0) { } __construct()... __destruct()... object(TheObject)#2 (0) { } __destruct()... Actual result: -------------- But I see this output : __construct()... object(TheObject)#1 (0) { } __construct()... __destruct()... __destruct()... NULL The automatic call of the __destruct() fonction on the seconde assignment destruct the both objects ! So the second assignment doesn't work !!! Thanks you for all you'll be able to do ;)