March 6, 2006 | PHP Scripting
I’ve updated the SQL class to use some native PHP 5, namely constructors and destructors and include some backward compatibility so PHP 4 does not freak out when it loads the class.
I’ll hopefully be making this 100% PHP 5 native soon enough as I’ll actually have a native PHP 5 environment to apply it to.
Namely the class makes use of register_shutdown_function and call_user_func_array to simulate constructor behavior on PHP 4. So by doing this:
if(phpversion('tidy') < 5)
$argcv = func_get_args();
call_user_func_array(array(&$this, '__construct'), $argcv);
I can now use __construct and __destruct in a PHP 4 compatible script and have the script be a little more PHP fun. The main advantage is that this script can close the db connection by itself now instead of having to do it in the page.
Hopefully this is useful to somebody…
You can view the entire source here, and download the zipped php file (basically just an extension change from the source file) here.