Re: __Destruct() functionality

From: Date: Sun, 27 Jun 2004 21:54:41 +0000
Subject: Re: __Destruct() functionality
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-10807@lists.php.net to get a copy of this message
Hello Gareth, __destruct will get executed during request shutdown after the communication has been shutdown. The only way to be able to write from within __destruct is to deinitialize it at the end of the script and therefore before the request is being finished. To do so you can use 'unset($object);' regards marcus Thursday, June 24, 2004, 1:27:30 PM, you wrote: > ok, > If this is fixed in cvs, I appologise - google wasn't suggesting that > this has come up before. > I've just been playing around with the __destruct() function a little > bit, and seeing exactly what I could do with it. > Basically, I have a company info class, and a logger class. The logger > class is loaded and called by the main script first, with the object > accessed through $LOG. It's only very basic $log->event(""); type > functions though. Now, this $LOG is then passed to the company info > class when that is initialised (the way it's set up, I'm deliberatly > avoiding extending classes for this). > From this point, companyInfo class takes the $LOG variable passed to it > in the __construct() method and assigns it to a private variable within > the class. > What I'm then trying to do within the __destruct() method is to then do: > if ($this->LOG->events) { > $this->LOG->event("Leaving company info class"); > } > However, what seems to be happening is that this is not being executed, > presumably as the variables/objects have been removed from memory before > __destruct() is called. I'm also getting no warning whatsoever. > It'd seem to me, that the ability to call variables within __destruct() > is quite valuable, as you're kinda limited to just printing output > otherwise (ok, not strictly true, but you get what I mean). > This is with php5-rc3 btw. > Can anybody confirm that this is 'intended' behaviour - because it seems > bloody odd if it is. > Cheers. > -- > Gareth Ardron -- Best regards, Marcus mailto:helly@php.net

« previous php.internals (#10807) next »