为什么不支持将PHP函数导入当前命名空间 [英] Why is Importing a PHP Function into the Current Namespace Unsupported

查看:156
本文介绍了为什么不支持将PHP函数导入当前命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 PHP文档

PHP名称空间支持三种别名或导入:别名类名称,别名接口名称和别名名称空间名称.请注意,不支持导入函数或常量.

PHP namespaces support three kinds of aliasing or importing: aliasing a class name, aliasing an interface name, and aliasing a namespace name. Note that importing a function or constant is not supported.

有人知道为什么不支持导入功能或常量的历史或技术背景吗?

Does anyone know the historical or technical context of why importing a function or constant is unsupported?

推荐答案

我联系了Jochem Maas(作者 of这个五岁的RFC ),尽管他不愿指出一个单一的原因(可以理解,因为他目前还没有深入参与命名空间系统),但他的三个因素是

I contacted Jochem Maas (the author of this five year old RFC), and while he was hesitant to pin point a single reason (understandably, as he isn't currently deeply involved with the namespace system), his three factors were

  1. 类名冲突比函数名冲突更像是现实世界中的问题

  1. Class name collisions were more of a real world problem than function name collisions

PHP函数和类位于引擎代码的不同区域,并且在解析use语句期间哪个是哪个方面存在技术上的障碍.

PHP functions and classes live in different areas of the engine code, and there were technical hurdles to parsing out which was which during a use statement.

对于如何处理自动加载器以及特定功能的导入/混淆,存在一些不确定性/意见分歧. (自动加载器是一个单独的系统,仅适用于类)

There was some uncertainty/difference of opinion on how to handle the autoloader and the importing/aliasing of specific functions. (The autoloader, a separate system, works with classes only)

最后,PHP的实用主义胜出了,这就是为什么我们拥有今天拥有的命名空间系统.

In the end, PHP's pragmatism won out, and that's why we have the namespace system we have today.

这篇关于为什么不支持将PHP函数导入当前命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆