PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
function __autoload($name)
{
require_once($name.'.php');
if (!class_exists($name))
{
trigger_error('Class '.$name.' not found in '.$name.'.php', E_USER_FATAL);
}
}
$foo = new foo();
function __autoload($name)
{
require_once($name.'.php');
if (!class_exists($name))
{
trigger_error('Class '.$name.' not found in '.$name.'.php', E_USER_FATAL);
}
}
//$foo = new foo();
if (class_exists('foo'))
{
//fatal
}
Sometime we want to check a class existance , but end up with USER_FATAL . I surprise that __autoload is also called when we use class_exists . So we can't use class_exists when we have an autoload function , huh ?
manual wrote:class_exists() will attempt to call __autoload by default, if you don't want class_exists() to call __autoload, you can set the parameter autoload to FALSE.