PHP

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • __construct __destruct in PHP 4

    0 answers - 3806 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    course __destruct (in php5) is not meant to be called by "userland" (as
    you called it). I just want to make sure all objects are stored as they
    should when a script ends. This kind of wrapper method is of course "lame"
    as you called it, but it would do what I need it to do, thought it is lame
    :) This is just to "simulate" something that is missing in PHP 4 and that I
    as a standard am working with. To close down database connections etc are
    not the purpose at this stage for me as PHP will take care of these
    resources by it self.
    , back to Sunday afternoon programming :)
    Best regards,
    Peter Lauri
    www.dwsasia.com - company web site
    www.lauri.se - personal web site
    www.carbonfree.org.uk - become Carbon Free
    Message
    From: Jochem Maas [mailto:jochem (AT) iamjochem (DOT) com]
    Sent: Sunday, January 28, 2007 4:27 PM
    To: Peter Lauri
    Cc: 'Larry E. Ullman'; php-general (AT) lists (DOT) php.net
    Subject: Re: [PHP] __construct __destruct in PHP 4
    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. 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, STDUT, etc.
    Best regards,
    Peter Lauri
    www.dwsasia.com - company web site
    www.lauri.se - personal web site
    www.carbonfree.org.uk - become Carbon Free
    Message
    From: Larry E. Ullman [mailto:LarryUllman (AT) DMCInsights (DOT) Com]
    Sent: Sunday, January 28, 2007 4:09 PM
    To: Peter Lauri
    Cc: php-general (AT) lists (DOT) php.net
    Subject: Re: [PHP] __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
    There is no destructor in PHP 4.
    Larry
    PS The manual has two sets of P documentation: one for PHP 4 &
    another for PHP 5. Make sure you're viewing the right set.

Re: __construct __destruct in PHP 4


max 4000 letters.
Your nickname that display:
In order to stop the spam: 8 + 7 =
QUESTION ON "PHP"

EMSDN.COM