php命名空间报错
PHPz
PHPz 2017-04-11 10:25:56
0
1
699

报错Parse error: syntax error, unexpected T_STRING in F:appwampserverAppServwwwnamespace.php on line 3


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

学习是最好的投资!

reply all(1)
大家讲道理

const 关键字只能用于定义类内常量,类外请使用 define。(PHP 5.3 之前)

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!