# __Destruct() functionality

- Thread: https://externals.io/message/10753
- Original archive: https://news-web.php.net/php.internals/10753
- Started by Gareth Ardron on 2004-06-24T11:27:30+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #10753 — Gareth Ardron — 2004-06-24T11:27:30+00:00

URL: https://externals.io/message/10753#10753

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

---

## #10807 — Marcus Boerger — 2004-06-27T21:54:41+00:00

URL: https://externals.io/message/10753#10807 · In reply to: #10753

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
