|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-07-13 15:33 UTC] Bertrand dot Willm at laposte dot net
Description:
------------
There is no recursive call to __destruct when it is not defined in a derived class.
There is not this problem with __construct.
This can be dangerous be cause if a destructor is declared, all the derived clas have to declare a __destruct to be sure that the destruction is done.
In other way __destruct is obligatory not to have problem, but this is not flexible.
Reproduce code:
---------------
class CBaseClass {
var $name;
function __construct($name) {
$this->name = $name;
echo "$this->name->CBaseClass::__construct()<br>";
}
function __destruct() {
echo "$this->name->CBaseClass::__destruct()<br>";
}
}
class CExtClass extends CBaseClass {
}
echo 'Creation of ExtObject<br>';
$ExtObject = new CExtClass('ExtObject');
echo 'End of script<br>';
Expected result:
----------------
Creation of ExtObject
ExtObject->CBaseClass::__construct()
End of script
Actual result:
--------------
Creation of ExtObject
ExtObject->CBaseClass::__construct()
End of script
ExtObject->CBaseClass::__destruct()
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 09:00:01 2025 UTC |
Try this simple CLI command: php -n -r 'class t { function __destruct() { echo "Bla\n";} } $o= new t;' For me it outputs Bla what means the destructor is called during shutdown. However it is possible that one of my pending patches causes the correct behavior. Please verify again.On PHP 5.0.0b2-dev (cgi-fcgi) (built: Jul 14 2003 20:08:40) there is no -r option. I try this: php -n and on the standard input: <? class t { function __destruct() { echo "Bla\n";} } $o= new t; ?> This should be equivalent. It works. What does not work is the following: php -n -r '<? class t { function __destruct() { echo "Bla\n";} } class u extends t {} $o= new u; ?>' As there is no -r on my php I enterred this: php -n and in the standard input: <? class t { function __destruct() { echo "Bla\n";} } class u extends t {} $o= new u; ?> This does not work.