Re: __construct __destruct in PHP 4

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

 



Peter Lauri wrote:
> Hi,
> 
>  
> 
> 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 :-)

Hi Peter,

As you probably already know, PHP 4 constructors are functions named
after the class

<?php
class Foo
{
    function Foo()
    {
        echo "in constructor";
    }
}
$a = new Foo;
?>

Although destructor emulation is implemented in the PEAR class
(destructor would be function _Foo), I don't recommend using a
destructor in PHP 4.  Instead, manually destruct your objects.  PEAR
does it with a shutdown function, so if performance is not a question,
by all means, use PEAR's implementation.  It has been battle-tested for
years and years.

However, I wouldn't bother with writing new code in PHP 4.  It will be
cheaper for you to switch hosting providers to one that allows you to
use PHP 5.  Why?  You will waste tons of time working around reference
issues that are non-existent in PHP 5 due to object handles.

Greg

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