#36831 [Bgs]: Trying to create a file in destructor fails

From: Date: Thu, 23 Mar 2006 11:51:45 +0000
Subject: #36831 [Bgs]: Trying to create a file in destructor fails
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-94808@lists.php.net to get a copy of this message
ID: 36831 User updated by: felho at avalon dot aut dot bme dot hu Reported By: felho at avalon dot aut dot bme dot hu Status: Bogus Bug Type: Class/Object related Operating System: * PHP Version: * New Comment: "Most parts of php are already shutdown when the engine calls the destructors after the script ends." My first thought was to choose documentation related bug. This is not mentioned in the manual on the page which is related to __destruct. "For the same reason you cannot output anything from a destructor." It is funny, that the example in the manual exactly do this. function __destruct() { print "Destroying " . $this->name . "\n"; } Previous Comments: ------------------------------------------------------------------------ [2006-03-23 12:34:36] helly@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Most parts of php are already shutdown when the engine calls the destructors after the script ends. For the same reason you cannot output anything from a destructor. ------------------------------------------------------------------------ [2006-03-23 12:24:08] felho at avalon dot aut dot bme dot hu Description: ------------ In case when an object is freed up at the end of the script file creation will fail in destructor. When I force this before the end of script the file will be created. Reproduce code: --------------- <?php class foo { function __construct() { fopen(date('YmdHim').'.const.txt', 'w'); mail('felho@x.hu', date('YmdHim').'.const.txt', ''); } function __destruct() { fopen(date('YmdHim').'.dest.txt', 'w'); mail('felho@x.hu', date('YmdHim').'.dest.txt', ''); } } $foo = new foo(); //$foo = 1; ?> Expected result: ---------------- Creating two files and sending two mails. Actual result: -------------- Only one file was created but two mails was sent. If you remove the comment on the last line, the second file was created too. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=36831&edit=1

« previous php.bugs (#94808) next »