Re: Re: Question about __destruct()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stut schreef:
> On 21 Oct 2008, at 22:08, Jochem Maas wrote:
>> Mike van Riel schreef:
>>> Dan Joseph wrote:
>>>> Hi,
>>>>
>>>> I want to make sure I completely understand __destruct() and when its
>>>> hit...
>>>>
>>>> Understand that it will run if all references to a particular object
>>>> are
>>>> removed, but is that also true when a page ends its execution?
>>>>
>>>> Example, I call a database class.  It constructs, connects, then my
>>>> page
>>>> pulls some stuff out of the database, and then the php script ends. 
>>>> Does
>>>> this also cause the deconstruct to execute?
>>>>
>>>
>>> When a script ends everything is released (with some small exceptions),
>>> thus also all references to instances of classes.
>>> Thus AFAIK a deconstructor will always be called at the end of script
>>> execution.
>>>
>>
>> but you have no control over what order dtors are called and you can't
>> make
>> any assumptions about state of file handles to STDIN/STDOUT and things
>> like
>> that ... personally I find dtors run at end of script to be nigh on
>> useless.
> 
> I use destructors to update dirty objects in memcache. 

care to eloborate ... sounds interesting.

I also use them
> in my template class to optionally automagically output the footer
> without needing an explicit call on each page.

not sure if I find that of much use, I see the validity but 1 LOC to
eplicitly output a page footer seems to me to be less of a wtf than
an(other) bit of auto-magic to save what is probably a very short simple
method call.

> They're far from useless.

true. but they are limited, there is no garantee any other object
will still exist when a particular dtor is run [at shutdown] which means a heavy OO
codebase cannot have object automated object interaction at shutdown ... there
are other gotchas (e.g. closed file descriptors to STDIN/STDOUT)

interaction with memcache though is a really good example. and I'd like to
learn a little more :-D

> -Stut
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux