解决方案 »
- SMTP Error: Could not connect to SMTP host.
- 请教一下function getgsr($order_id, $goods_id)函数调用的问题
- 哪里有PHP写的网上商店的原代码,给看看,谢谢!!!!100分!!
- 只有十分了,跪求一段关于文件上传的代码...
- 不看不知道呀!
- php的安装程序到底到哪里下载
- 做登录的问题!
- 看看这个吧!!!
- 》》》》PHP 对 COM 的支持 《《《《
- 文件上传,一直localhost等待是什么情况
- 为什么我每次获取验证码的值和存进服务器里面的session值是不一致的,真心弄不懂。。。望各位大哥解答。。。谢谢
- 急急~~~~~
//use test1;
function test2()
{
echo __FUNCTION__;
}
echo test1\test();
为什么不用use 呢?用use也出错。
在test2.php中顶部声明 namespace test1; 也还是不能直接使用 echo test();
include 'test1.php';
function test2()
{
echo __FUNCTION__;
}
echo test();
而且use test1;这种写法本身就是不对的。
像use test1/classname 这种写法才行,下面实例化函数的时候
new classname; //php会在test1命名空间下找classname的类,如果没有找到就自动装载了。
test1.php
<?php
namespace test1;
class test
{
function test1()
{
echo 'fun:'.__FUNCTION__;
}
}
test2.php:
<?php
use test1;
include "test1.php";
$t=new test();
echo $t->test1();感觉use还是没有起作用。
use test1\test;$t = new test();
echo $t->test1();或者include "test1.php";
use test1\test as test2;$t = new test2();
echo $t->test1();或者include "test1.php";$t = new test1\test();
echo $t->test1();
use test1\test as test2;
或者
use test1\test; 这个 其实相当与 use test1\test as test;上面的test1是命名空间后面跟着的test是test1命名下的test类
然后实例化 new test() 等价与 new test1\test();
这个就是use的作用,就是别名的意思。