PHP>

CLASSES

Classes are fun... BUT... one of my customers is running PHP 4 still.  What a pain in the arse!

Luckily for me.. the guys at 'Imagine and innovate' have a nice solution.


PHP 4 Constructor and Destructor

Here is a way to have constructor and destructor functions in php4:

/**
* Because php 4 does not have a proper OOP implementation
* here is a way to have php4 destructor and constructor
*
*/
class demoClass
{
    // {{{ constructor
    /**
    * php4 class contructor
    *
    * @return object
    */
    function demoClass() {
        //destructor
        register_shutdown_function(array(&$this, '__destruct'));

        //constructor
        $argcv = func_get_args();
        call_user_func_array(array(&$this, '__construct'), $argcv);
    }
    // }}}

    // {{{ __construct()
    /*
    * constructor function implementation
    */
    function __construct() {
        //code for constructor goes here
    }
    // }}}

    //{{{ __destruct()
    /*
    * destructor function implementation
    */
    function __destruct() {
        //code for destructor goes here
    }
    //}}}
}