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

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

WBOY
Release: 2016-06-13 13:33:42
Original
1162 people have browsed it

关于 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";
    }
}
 
?>
Copy after login

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();
?>

Copy after login

这里有报错了。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
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