include "test/C.php"; use Test\Driver as p; $c=new p\C(); $c->test();
恩,这样写是可以的。但是必须要这么写吗?不好意思,请问use 不是引用当前的命名空间里了吗?
这样子也可以namespace Test\Driver; include "test/C.php"; $c=new C(); $c->test();use 是引用命名空间 正确的用法我也不是很清楚
现在操作上,感觉use没起到什么作用。
刚才恶补了一下,现炒现卖 使用命名空间的三种方法 include "test/C.php"; $c=new Test\Driver\C(); $c->test(); include "test/C.php"; use Test\Driver; $c=new Driver\C(); $c->test(); include "test/C.php"; use Test\Driver as p; $c=new p(); $c->test();
只要你 include 了,里面的所用类就都加载了什么选择性载入是不存在的,自欺欺人的
第一种和第三种我都明白include "test/C.php"; use Test\Driver; $c=new Driver\C(); 就是不明白这里的Driver 是什么意思 $c->test();
呀,手欠做了个试验 <?php namespace Test\Driver; use Test\Driver; class C { function test() { echo "c"; } }?>test.php <?php
include "test/C.php"; //use Test\Driver; $c=new Test\Driver\C(); $c->test(); echo "<br>";
?>这样写又报错了
include "test/C.php"; //use Test\Driver; $c=new Driver\C(); $c->test(); echo "<br>"; 报错信息 ( ! ) SCREAM: Error suppression ignored for ( ! ) Fatal error: Class 'Driver\C' not found in E:\hongyunlai\thinkphp32\test.php on line 14 Call Stack # Time Memory Function Location 1 0.0005 247472 {main}( ) ..\test.php:0
use Test\Driver as p;
$c=new p\C();
$c->test();
include "test/C.php";
$c=new C();
$c->test();use 是引用命名空间
正确的用法我也不是很清楚
使用命名空间的三种方法
include "test/C.php";
$c=new Test\Driver\C();
$c->test();
include "test/C.php";
use Test\Driver;
$c=new Driver\C();
$c->test();
include "test/C.php";
use Test\Driver as p;
$c=new p();
$c->test();
use Test\Driver;
$c=new Driver\C(); 就是不明白这里的Driver 是什么意思
$c->test();
$c=new Driver\C(); 只需取命名空间的最后一节即可
<?php
namespace Test\Driver;
use Test\Driver;
class C
{
function test()
{
echo "c";
}
}?>test.php
<?php
include "test/C.php";
//use Test\Driver;
$c=new Test\Driver\C();
$c->test();
echo "<br>";
?>这样写又报错了
include "test/C.php";
//use Test\Driver;
$c=new Driver\C();
$c->test();
echo "<br>";
报错信息
( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Class 'Driver\C' not found in E:\hongyunlai\thinkphp32\test.php on line 14
Call Stack
# Time Memory Function Location
1 0.0005 247472 {main}( ) ..\test.php:0