Home  >  Article  >  Backend Development  >  php一个命名空间的坑

php一个命名空间的坑

WBOY
WBOYOriginal
2016-06-23 13:34:14861browse

最近一直用Thinkphp框架开发,3.2版本的,用到了命名空间.遇到了一个坑:

A.class.php

<?phpnamespace nsa;class A {    function fa(){        echo 'fa';    }}

b.php

<?phprequire_once('A.class.php');use nsa\A; $a = new A();        //这样不会错$a->fa(); $type = 'A';        //这样写,new时会出错$aa = new $type();  //错误信息 Class 'A' not found$aa->fa(); $type2 = 'nsa\\A';  //写成这样就对了,可以new了$aaa = new $type2();$aaa->fa();

大概意思就这样,记下这个坑.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn