php-developer-list | 2001122
Date: 12/28/01
- Next message: caldwell <email protected>: "[PHP-DEV] Bug #14745: ulink handles relative links oddly"
- Previous message: Adam Dickmeiss: "[PHP-DEV] Need karma to close bugs 14602, 14616"
- In reply to: cox <email protected>: "[PHP-DEV] Bug #14744: destructor emulation problem (references?)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
ID: 14744
User updated by: cox <email protected>
Reported By: cox <email protected>
Status: Open
Bug Type: Scripting Engine problem
Operating System: Linux
PHP Version: 4.1.0
New Comment:
The paste seems that wasn't very good, sorry. The correct code:
<?php
$GLOBALS['_call_destruct'] = null;
class foo {
var $a = "orig value";
function foo() {
$this->register();
}
function register() {
$GLOBALS['_call_destruct'] =& $this;
}
}
function _destruct() {
$foo =& $GLOBALS['_call_destruct'];
echo "in destructor: {$foo->a}\n";
}
register_shutdown_function('_destruct');
$foo = new Foo;
$foo->a = "new value";
echo "updated value: {$foo->a}\n";
?>
Previous Comments:
------------------------------------------------------------------------
[2001-12-28 13:54:45] cox <email protected>
I catched a bug in the PEAR object destructor emulation and could isolate the problem in this script.
<?php
$GLOBALS['_call_destruct'] = null;
class foo {
var $a = "orig value";
function foo() {
$this->register();
}
function register() {
$GLOBALS['_call_destruct'] =& $this;
}
}updated value: new value
in destructor: orig value
function _destruct() {
$foo =& $GLOBALS['_call_destruct'];
echo "in destructor: {$foo->a}\n";
}
register_shutdown_function('_destruct');
$foo = new Foo;
$foo->a = "new value";
echo "updated value: {$foo->a}\n";
?>
This outputs:
updated value: new value
in destructor: orig value
Which means that the value of the "a" property is lost. Really the whole object is equal to the object comming from the constructor instead of the modified one. This doesn't ocurr if you register the object in a method out the constructor.
The correct output of this should be:
updated value: new value
in destructor: new value
-- Tomas V.V.Cox
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=14744&edit=1
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: caldwell <email protected>: "[PHP-DEV] Bug #14745: ulink handles relative links oddly"
- Previous message: Adam Dickmeiss: "[PHP-DEV] Need karma to close bugs 14602, 14616"
- In reply to: cox <email protected>: "[PHP-DEV] Bug #14744: destructor emulation problem (references?)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

