#38018 [Opn->Bgs]: __destruct called if __wakeup threw an exception

From: Date: Wed, 05 Jul 2006 21:36:26 +0000
Subject: #38018 [Opn->Bgs]: __destruct called if __wakeup threw an exception
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-99148@lists.php.net to get a copy of this message
ID: 38018 Updated by: tony2001@php.net Reported By: php dot bugs at login dot hedim dot ch -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: FreeBSD PHP Version: 5.1.4 New Comment: Change your code to this: $var = new Foo; $str = serialize($var); unserialize($str); and voila - no second destructor call. The first destructor is called for the temporary var. Previous Comments: ------------------------------------------------------------------------ [2006-07-05 20:31:32] php dot bugs at login dot hedim dot ch Description: ------------ If __wakeup threw an exception when unserializing an object, __destruct is called on that object. For the same reasons as __destruct is not called if __construct threw an exception (see bug #29368), it should not be called here either. Reproduce code: --------------- class Foo { function __wakeup() { throw new Exception; } function __destruct() { echo "hello from destructor\n"; } } unserialize(serialize(new Foo)); Expected result: ---------------- hello from destructor (from the destructor of the object to be serialized) Actual result: -------------- hello from destructor (from the destructor of the object to be serialized) hello from destructor (from the destructor of the object that fails to unserialize) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38018&edit=1

« previous php.bugs (#99148) next »