未命名

admin3年前IT技术1337

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


相关文章

windows11 的windows安全中心 无法打开

解决方案:1.使用管理员权限从搜索或开始菜单中打开 Windows PowerShell。2.复制并粘贴Get-AppxPackage Microsoft.SecHealthUI -AllUsers...

KindEditor的图片仓库绑定用户ID的方法

在新建目录的时候,只能一个一个的建立,不能一次性的建两个目录或者在空目录路径之后新建目录...

WireGuard 安装脚本

WireGuard 安装脚本

 执行结束后,会输出一个二维码,可直接用 WireGuard App 扫描导入。4. 客户端配置文件路径/etc/wireguard/client.conf可复制到 Windows、Mac、...

Android Studio下载sdk失败的解决方案

在浏览器打开这个网站http://ping.chinaz.com/dl.google.com或者:https://www.ping.cn/ping/dl.google.com他会列出一个ip列表,挨个...

vue2 学习笔记

页面写法与cli写法 函数方法 写法不一样 方法method不要写在date里路由表其实很容易,官方文档不是写给人看得 ,是装逼用的...

本人安装Magento2.4.6安装踩坑大集合

1.痛点1 composer 的版本查看命令输入错误,导致我以为我安装失败 composer --version或者 composer -Vcomposer create-proj...

发表评论    

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