Home  >  Article  >  Backend Development  >  关于 namespace 和 use的报错,该怎么处理

关于 namespace 和 use的报错,该怎么处理

WBOY
WBOYOriginal
2016-06-13 13:33:421121browse

关于 namespace 和 use的报错

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php #test.class.php
namespace myNamespace;
 
class MyClass {
    public function Show(){
        echo "hello";
    }
}
 
?>

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php #index.php
    require_once "test.class.php";
    $c1 = new myNamespace::MyClass();
    $c1->Show();
?>


这里有报错了。Fatal error: Class 'myNamespace' not found in /var/www/HelloWorld/index.php on line 4

用明明空间的方式引用不是这样写的?

------解决方案--------------------
$c1 = new myNamespace\MyClass();可以的
------解决方案--------------------
$c1= new myNamespace\MyClass(); 

参考
http://jackyrong.iteye.com/blog/900964
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