php-src/ext/spl/tests/spl_autoload_001.phpt

137 lines
2.5 KiB
Plaintext
Raw Normal View History

2005-03-02 01:14:41 +00:00
--TEST--
SPL: spl_autoload() and friends
2005-03-02 01:14:41 +00:00
--INI--
include_path=.
--FILE--
<?php
echo "===EMPTY===\n";
var_dump(spl_autoload_extensions());
2005-03-02 01:14:41 +00:00
try
{
spl_autoload("TestClass");
}
catch(Exception $e)
{
echo 'Exception: ' . $e->getMessage() . "\n";
}
$test_exts = array(NULL, "1", ".inc,,.php.inc", "");
foreach($test_exts as $exts)
{
echo "===($exts)===\n";
try
{
spl_autoload("TestClass", $exts);
}
catch(Exception $e)
{
echo 'Exception: ' . $e->getMessage() . "\n";
}
}
try
{
spl_autoload_extensions(".inc,.php.inc");
spl_autoload("TestClass");
}
catch(Exception $e)
{
echo 'Exception: ' . $e->getMessage() . "\n";
}
function TestFunc1($classname)
{
echo __METHOD__ . "($classname)\n";
}
function TestFunc2($classname)
{
echo __METHOD__ . "($classname)\n";
}
echo "===SPL_AUTOLOAD()===\n";
spl_autoload_register();
try
{
var_dump(spl_autoload_extensions(".inc"));
2005-03-02 01:14:41 +00:00
var_dump(class_exists("TestClass", true));
}
catch(Exception $e)
{
echo 'Exception: ' . $e->getMessage() . "\n";
}
echo "===REGISTER===\n";
2005-03-03 00:20:57 +00:00
spl_autoload_unregister("spl_autoload");
2005-03-02 01:14:41 +00:00
spl_autoload_register("TestFunc1");
spl_autoload_register("TestFunc2");
spl_autoload_register("TestFunc2"); /* 2nd call ignored */
spl_autoload_extensions(".inc,.class.inc"); /* we do not have spl_autoload_registered yet */
try
{
var_dump(class_exists("TestClass", true));
}
catch(Exception $e)
{
echo 'Exception: ' . $e->getMessage() . "\n";
}
echo "===LOAD===\n";
spl_autoload_register("spl_autoload");
var_dump(class_exists("TestClass", true));
echo "===NOFUNCTION===\n";
try
{
spl_autoload_register("unavailable_autoload_function");
}
catch(Exception $e)
{
echo 'Exception: ' . $e->getMessage() . "\n";
}
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
===EMPTY===
2005-08-10 06:10:04 +00:00
string(9) ".inc,.php"
2008-02-02 04:03:03 +00:00
%stestclass.inc
2005-03-02 01:14:41 +00:00
Exception: Class TestClass could not be loaded
===()===
Exception: Class TestClass could not be loaded
===(1)===
Exception: Class TestClass could not be loaded
===(.inc,,.php.inc)===
2008-02-02 04:03:03 +00:00
%stestclass
%stestclass.php.inc
2005-03-02 01:14:41 +00:00
Exception: Class TestClass could not be loaded
===()===
Exception: Class TestClass could not be loaded
Exception: Class TestClass could not be loaded
===SPL_AUTOLOAD()===
string(4) ".inc"
2005-03-02 01:14:41 +00:00
Exception: Class TestClass could not be loaded
===REGISTER===
TestFunc1(TestClass)
TestFunc2(TestClass)
bool(false)
===LOAD===
TestFunc1(TestClass)
TestFunc2(TestClass)
2008-02-02 04:03:03 +00:00
%stestclass.class.inc
2005-03-02 01:14:41 +00:00
bool(true)
===NOFUNCTION===
2008-02-02 03:20:51 +00:00
Exception: Function 'unavailable_autoload_function' not found (function 'unavailable_autoload_function' not found or invalid function name)
2005-03-02 01:14:41 +00:00
===DONE===