note 80680 deleted from language.oop5.autoload by bjori
| From: | bjori@php.net | Date: | Mon, 26 May 2008 11:27:13 +0000 |
| Subject: | note 80680 deleted from language.oop5.autoload by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-139786@lists.php.net to get a copy of this message | ||
Note Submitter: alexanderpas at yahoo dot co dot uk
----
I think i've found the holy grail....
use a wrapper function for the new statement, and all your problems are solved.
<?php
/**
* PHP magic function, loads Objects automatically when needed.
*
* @param string class
* @see http://php.net/manual/language.oop5.autoload.php
*/
function __autoload($class)
{
if (file_exists("./$class.php"))
{
require_once("./$class.php");
}
else
{
throw new Exception("Unable to find required file to load $class");
}
}
/**
* Wrapper for PHP new Class statement.
*
* @param string class
* @param array arguments
* @return object class or bool FALSE
*/
function new_class($class, array $arguments = array())
{
try
{
class_exists($class);
}
catch(Exception $exception)
{
echo $exception->getMessage();
return FALSE;
}
return new $class($arguments);
}
?>