destructor access to constants

php.internals

Ulf Wendel

23 years ago
Hi, I'm wondering if it's a bug to give automatically called destructors access to constants (PHP Version 5.0.0b1). I'd expect to be neither able to access global variables nor constants after script termination (die()). Ulf $dtor = 'global $dtor variable is visible'; define('DTOR', 'DTOR constant is visible'); class dtor { function __destruct() { global $dtor; printf('$dtor = "%s"<br> DTOR = "%s"<br>', $dtor, DTOR); } } $d1 = new dtor(); unset($d1); $d2 = new dtor(); die(); generated output: $dtor = "global $dtor variable is visible" DTOR = "DTOR constant is visible" $dtor = "" DTOR = "DTOR constant is visible"

(Marcus Börger)

23 years ago
Hello Ulf, Sunday, July 6, 2003, 12:27:00 PM, you wrote: UW> Hi, UW> I'm wondering if it's a bug to give automatically called destructors UW> access to constants (PHP Version 5.0.0b1). I'd expect to be neither able UW> to access global variables nor constants after script termination (die()). UW> Ulf UW> $dtor = 'global $dtor variable is visible'; UW> define('DTOR', 'DTOR constant is visible'); UW> class dtor { UW> function __destruct() { UW> global $dtor; UW> printf('$dtor = "%s"<br> DTOR = "%s"<br>', $dtor, DTOR); UW> } UW> } UW> $d1 = new dtor(); UW> unset($d1); UW> $d2 = new dtor(); UW> die(); UW> generated output: UW> $dtor = "global $dtor variable is visible" UW> DTOR = "DTOR constant is visible" UW> $dtor = "" UW> DTOR = "DTOR constant is visible" Global variables are a bit complicated but constants are either bound to the class so they are obviously available in instance destruction or as in your case they were registered in the global space and hence destructed after all script action is finished which includes automatic destructor calls from GC.
-- Best regards, Marcus mailto:helly@php.net

Ulf Wendel

23 years ago
Marcus Börger wrote:
> Global variables are a bit complicated but constants are either bound to the > class so they are obviously available in instance destruction or as in your > case they were registered in the global space and hence destructed after all > script action is finished which includes automatic destructor calls from GC.
Hi Markus, is the this behaviour a feature or a bug? With other words can I rely on the following: ... $__die = false; die() ... function __destruct() { global $__die_called; if (isset($__die)) // script is still running print "... unless someone has unset $__die."; else // script has ended print "that's it folks!"; } Ulf