PHP 命名空间笔记
1.php文件代码如下
<pre>
<?php
//我用这样的命名空间表示处于blog下的article模块
namespace BlogArticle;
class Comment {
function __construct(){ //初始化对象,将初始化值放在括号内
echo'初始化1';
}
}
?>
</pre>
2.php文件代码如下
<pre>
<?php
require '1.php';
//调用BlogArticle空间的类
$article_comment = new BlogArticleComment();
/*require '1.php';
use BlogArticleComment;
$article_comment = new Comment();*/
/*namespace BlogArticle;
require '1.php';
$article_comment = new Comment();*/
?>
</pre>