Re: __construct __destruct in PHP 4

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

 



Peter Lauri wrote:
> Hi,
> 
> Yes I have been reading both sections and is aware of the different sections
> for PHP 4 and 5. I was just hoping there was something missing in the manual
> for PHP 4 as I'd love to have a __destruct method to work with. There are
> other solutions around this. Basically I just want to make sure that the
> objects that have a save() method are saved correctly before they are
> destroyed. With PHP 4 I just need to do this "manually". I could probably
> just write a cleanup function that will be executed in the end of each
> scripts that checks if objects have a save() method and then executes that
> one. Or better: Check if there is a method __destruct() existing and use
> that when cleaning up. Then it would be forward compatible with PHP 5 as
> well :)

alternative:

have each object register itself with a 'stack' and register a shutdown function
which automatically calls the save() method of each object in said stack...
be careful to always using the 'reference' operator.

I wouldn't bother to try and make it php4/php5 compatible - the reference operator
of itself will make sure that you have to change the code for php5, besides that __destruct()
is not 'meant' to be called by userland code - and as far as I can tell it's
a bit lame (there is no garanteed order of destruction so you can't rely on other object still
being around and IIRC [somebody correct me if I'm wrong please] things like DB connections
are also gone by the time __destruct() is called - the same goes for access to STDIN, STDOUT, etc.

> 
> Best regards,
> Peter Lauri
> 
> www.dwsasia.com - company web site
> www.lauri.se - personal web site
> www.carbonfree.org.uk - become Carbon Free
> 
> 
> -----Original Message-----
> From: Larry E. Ullman [mailto:LarryUllman@xxxxxxxxxxxxxxx] 
> Sent: Sunday, January 28, 2007 4:09 PM
> To: Peter Lauri
> Cc: php-general@xxxxxxxxxxxxx
> Subject: Re:  __construct __destruct in PHP 4
> 
>> I have been trying going thru the PHP manual to find if there are any
>> equivalent to the __contruct and __destruct in PHP 4, but I cannot  
>> find any
>> solution for this part. I know it was introduced in PHP 5, but as  
>> __sleep
>> and __wakeup exist in PHP 4 already I was hoping there is something  
>> like
>> __init and __die in PHP 4 :-)
> 
> In PHP 4 the constructor has the same name as the class (like C++). See
> http://us3.php.net/manual/en/language.oop.constructor.php
> 
> There is no destructor in PHP 4.
> 
> Larry
> 
> PS The manual has two sets of OOP documentation: one for PHP 4 &  
> another for PHP 5. Make sure you're viewing the right set.
> 

-- 
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