ID: 22655 User updated by: stanislav at shramko dot com Reported By: stanislav at shramko dot com -Status: Feedback +Status: Open Bug Type: Scripting Engine problem Operating System: WinXP PHP Version: 4.3.0 New Comment:
I thought that the variable should be unset in the class as well, cause it was passed into constructor by reference. Also it is disposed in the global scope so should be removed from everywhere. Now it seems that the variable is unset in the global scope, not in local ones. Such behavior of PHP seems not very predicable to me. The only solution I found is to assign a null value to the variable manually. It looks like a workaround though, not like the right way to do things. Previous Comments: ------------------------------------------------------------------------ [2003-03-12 17:15:41] [EMAIL PROTECTED] And what did you expect the output to be? ------------------------------------------------------------------------ [2003-03-12 02:15:55] stanislav at shramko dot com I was very discouraged about the behavior of unset() function with variables which are contained in objects in the same time. Also I'm slightly mad about references to NULL and so on. <?php // two test classes class a { var $a = null; function a( &$b ) { $this->a = &$b; } } class b { var $b = 5; } // ---------- the main part ------------ // alas, I need to use destructors $b = &new b(); $a = &new a( $b ); var_dump( $a ); // checking the object's state $b->b = 3; // changing it var_dump( $a ); // Note that value was changed... unset( $b ); // what are we waiting for? var_dump( $a ); // but the object's field wasn't affected $b = null; var_dump( $a ); // there's no way to destroy this blamed property echo "------------------------------------------------------------\n"; // but in case if we will try to assign a null value to this field whilst // the object is in it's initial state, we're getting another results $b = &new b(); $a = &new a( $b ); var_dump( $a ); $b->b = 3; var_dump( $a ); // Note that value was changed... $b = null; var_dump( $a ); // I see, it's a great way to dispose a field of an object :) // this reference to NULL looks pretty well, isn't it? :) ?> I've lost the sence of the whole situation at this point. Regards, Stanislav. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=22655&edit=1