PHP 预定义接口和SPL - 版本检查是否足够?
这也许是一个显而易见的问题,但我想确定一下。
我正在尝试找出“预定义接口”出现在哪个版本中PHP。我的假设是 5.0.0,因为这是根据文档添加 SPL 接口的时候。
此外,这些是否可以通过配置或重新编译来禁用,或者可以安全地假设版本检查满足它们的存在?为什么它们甚至与 SPL 分开,区别在于它们永远无法关闭,而 SPL 可以关闭? (至少在 5.3.0 之前)
This is perhaps an obvious question, but I want to be sure.
I'm trying to work out in which version the "Predefined Interfaces" appeared in PHP. My assumption is 5.0.0, as this is when the SPL interfaces were added according to the docs.
Furthermore, can these ever be disabled via configuration or recompile, or can one safely assume a version check satisfies their presence? Why are they even separated from the SPL, is the differentiator just that these can't ever be turned off, whilst the SPL can be? (at least prior to 5.3.0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在此处找到每个 SPL 接口的可用版本。有些是5.0之后添加的。并且根据手册,从 PHP 5.3.0 开始,无法禁用 SPL 。
You can find since what version each SPL interface is available here. Some were added after 5.0. And according to the manual as of PHP 5.3.0 SPL can't be disabled.
对于何时添加接口或差异是什么(在 PHP CVS 中挖掘五分钟并没有产生差异),我没有比您的假设更好的答案。
但是,有一种万无一失的方法来检查它们是否存在,而不是依赖于版本检查:
interface_exists
。对于 PHP 版本 5.0.0 和 5.0.1,您必须改为执行class_exists
。所以:
不是最漂亮的,但它绝对涵盖了所有基础。
I don't have a better answer than your assumptions for when the interfaces were added, or what the differentiator is (five minutes digging in the PHP CVS didn't produce one).
However, there is a bulletproof way to check for their existence instead of relying on a version check:
interface_exists
. For PHP versions 5.0.0 and 5.0.1, you will have to doclass_exists
instead.So:
Not the prettiest, but it definitely covers all bases.
目前,手册仅显示属于每个接口的方法的版本信息。该版本信息可以在页面顶部方法原型上方找到(info)。
因此,单击方法描述并查看其中列出的内容。
这些接口根本不是 SPL 扩展的一部分,并且无法启用或禁用它们。它们需要在 Zend 引擎中实现;不可能做他们在扩展中所做的事情,即 SPL。
不管怎样,我不久前提出了一个关于提供版本信息的功能请求 (#49927)在类(因此也是界面)概述/概要页面上。感谢您提醒我它存在并且很有用!
Currently, the manual only displays version information for the methods belonging to each interface. This version information can be found at the top of the page above the method prototype (info).
So, click through to the method description(s) and see what is listed there.
Those interfaces are not part of the SPL extension at all and there is no enabling or disabling of them. They were required to be implemented in the Zend engine; it would not be possible to do what they do in an extension, which the SPL is.
For what it is worth, I opened a feature request (#49927) a while ago about making version information available on the class (and therefore also interface) overview/synopsis pages. Thanks for reminding me that it exists and would be useful!