Pages

Showing posts with label OOP. Show all posts
Showing posts with label OOP. Show all posts

Wednesday, August 24, 2005

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