测试.php
<?php
$a = 'D:/mydomain/Slim/Lib/Table.php';
$b = '\Slim\Lib\Table';
foreach (array($a, $b) as $value)
{
if (file_exists($value))
{
echo "file_exist";
include_once($value);
new Table();
}
else if (class_exists($value))
{
echo "class_exist";
$class = new $value();
}
else
{
echo "error";
}
}
?>
和 D:/mydomain/Slim/Lib/Table.php
<?php
class Table {
function hello()
{
echo "test";
}
function justTest()
{
echo "just test";
}
}
?>
当我在浏览器中执行 test.php 时,输出结果是:
file_exist 致命错误:无法在第 2 行的 D:/mydomain/Slim/Lib/Table.php 中重新声明类表
class_exist 的 if 语句未触发。命名空间 \Slim\Lib\Table 永远不存在。