Home >Backend Development >PHP Tutorial >php namespace error
Parse error: syntax error, unexpected T_STRING in F:appwampserverAppServwwwnamespace.php on line 3
<code> <?php namespace Article; const PATH = '/article'; function getCommentTotal() { return 100; } class Comment { } namespace MessageBoard; const PATH = '/message_board'; function getCommentTotal() { return 300; } class Comment { } //调用当前空间的常量、函数和类 echo PATH; ///message_board echo getCommentTotal(); //300 $comment = new Comment(); //调用Article空间的常量、函数和类 echo \Article\PATH; ///article echo \Article\getCommentTotal(); //100 $article_comment = new \Article\Comment(); ?> </code>
Parse error: syntax error, unexpected T_STRING in F:appwampserverAppServwwwnamespace.php on line 3
<code> <?php namespace Article; const PATH = '/article'; function getCommentTotal() { return 100; } class Comment { } namespace MessageBoard; const PATH = '/message_board'; function getCommentTotal() { return 300; } class Comment { } //调用当前空间的常量、函数和类 echo PATH; ///message_board echo getCommentTotal(); //300 $comment = new Comment(); //调用Article空间的常量、函数和类 echo \Article\PATH; ///article echo \Article\getCommentTotal(); //100 $article_comment = new \Article\Comment(); ?> </code>
The const keyword can only be used to define constants within a class. Please use define outside the class. (Before PHP 5.3)