php namespace与use的问题
/test文件夹下建立C.php文件,内容
<?php
namespace Test\Driver;
class C
{
function test()
{
echo "c";
}
}
?>
/下建立test.php文件,内容
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
include "test/C.php";
use Test\Driver;
$c=new C();
$c->test();
echo "<br>";
?>
</body>
</html>
运行错误:
( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Class 'C' not found in E:\hongyunlai\thinkphp32\test.php on line 14
Call Stack
# Time Memory Function Location
1 0.0006 247520 {main}( ) ..\test.php:0
------解决方案--------------------你的命名空间是 Test\
Driver
$c=new
Driver\C(); 只需取命名空间的最后一节即可