未命名

admin3年前IT技术1296

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


相关文章

Adobe  2025 破解方法

Adobe 2025 破解方法

Adobe  2022 破解方法 Adobe  2023 破解方法Adobe  2024 破解方法Adobe&...

云图框架

 https://themes.getbootstrap.com/云图框架 ...

magento2.x系统加速

magento2.x系统加速

1:在根目录运行以下命令,全站生成静态bin/magento setup:static-content:deploy2:编译整个网站,让网站加速50%  注意事项:要把PHP脚本内存限制设置...

解决Centos7系统更新时报错:Could not resolve host: mirrorlist.centos.org; 未知的错误

1、背景        centos7系统在执行:sudo yum update,发生错误;1.1、错误描述       ...

sublime编译运行PHP

创建PHP编译系统添加 PHP 的 build system,如图所示, Tools->Build System-> New Build System :新建一个,默认的内容是:{&nbs...

美国年轻人都在玩哪些App[转]

美国年轻人都在玩哪些App[转]

Facebook 它对我们这个年龄的人来说已经死了,Facebook 是我们中学时候玩儿的,但是现在就像尴尬的家庭晚宴一样鸡肋,你会经常遇到这个问题:「别人都用 Facebook,你怎么不用?」(貌似...

发表评论    

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