未命名

admin3年前IT技术1367

<?php

namespace Article;

class Comment { }


namespace MessageBoard;

class Comment { }


//调用当前空间(MessageBoard)的Comment类

$comment = new Comment();


//调用Article空间的Comment类

$article_comment = new \Article\Comment();

?>


别名和导入

别名和导入可以看作是调用命名空间元素的一种快捷方式。PHP并不支持导入函数或常量。

它们都是通过使用use操作符来实现:

<?phpnamespace Blog\Article;class Comment { }//创建一个BBS空间(我有打算开个论坛)namespace BBS;//导入一个命名空间use Blog\Article;//导入命名空间后可使用限定名称调用元素$article_comment = new Article\Comment();//为命名空间使用别名use Blog\Article as Arte;//使用别名代替空间名$article_comment = new Arte\Comment();//导入一个类use Blog\Article\Comment;//导入类后可使用非限定名称调用元素$article_comment = new Comment();//为类使用别名use Blog\Article\Comment as Comt;//使用别名代替空间名$article_comment = new Comt();?>


相关文章

Magento2.x 设置前台页面的路径

 解决方案:M2 后台--> STORES --> Configuration --> ADVANCED -->Developer -->Debug --&g...

excel引用另外一个sheet里的数据

公式如下=Sheet3!H6...

openclaw安装教程

http://127.0.0.1:18789,在设置里填 API。重新运行孵化命令:在终端输入 openclaw hatchWindows10 中国大陆环境 从零安装【原版 OpenClaw】+配置N...

删除系统还原点,可以释放大量c盘空间

删除系统还原点,可以释放大量c盘空间

删除系统还原点,可以释放大量c盘空间...

免费教Php,前端开发,asp.net,c#,拯救无业青年

免费教Php,前端开发,asp.net,c#,拯救无业青年

从事互联网开发15年,如果你对计算机编程有兴趣,都可以来找我我能教你的有如下技术:asp.net php c# javascript 前端开发 ...

使用acme.sh申请Let‘s Encrypt的SSL证书并安装的步骤

在CentOS 7上使用acme.sh申请Let’s Encrypt的SSL证书并安装在Nginx服务器的步骤,可以分为以下几个主要步骤:一、安装acme.sh安装必要的工具:确保你的系统中已安装so...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。