php 为什么new一个对象后面要加一个反斜杠

因为使用了php的命名空间,演示代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
// 创建命名空间Article
namespace Article;
class Comment { }
 
// 创建命名空间MessageBoard
namespace MessageBoard;
class Comment { }
 
//调用当前空间(MessageBoard)的Comment类
$comment new Comment();
 
//调用Article空间的Comment类
$article_comment new \Article\Comment();

posted on 2017-12-15 10:03  辛巽东  阅读(5133)  评论(0编辑  收藏  举报

导航