php一个命名空间的坑

WBOY
Release: 2016-06-23 13:34:14
Original
860 people have browsed it

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

A.class.php

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

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();
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!