未命名

admin2年前IT技术968

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


相关文章

Apache的几种常用配置

Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。     ...

yt-dlp+ffmpeg

1. 安装Python和ffmpegPython:安装时把pip和添加系统环境变量都选上ffmpeg:下载好exe文件,把目录添加到系统环境变量就行2. 安装yt-dlppip install yt-...

magento1.9x系统加速

1.设置magento数据库模型 为单表查询:   在System > Configuration > Catalog > FrontEnd设置 ‘U...

过滤emoji表情的正则表达式

\p{Cs}?imageView2/2/w/300/interlace/1/q/90^[\u4e00-\u9fa5]+$...

php上传路径问题

php图片上传不认"\"C:\Users\Administrator\Desktop\"只认C:/Users/Administrator\Desktop/...

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

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

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

发表评论    

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