我可以在 PHP 中实现组类型吗?
我不确定这是否称为组类型,但我的意思是:
由于 PHP 是动态类型的,因此这会增加延迟,这是可以理解的。是否可以在 PHP 中创建某种类型系统,以便
可以将 ints、floats 和其他数值分组到 Number 下,以及对其他类型进行分组以提高运行时速度,以便如果变量是 Number 类型,则在运行时,PHP 可以快速地只检查该组,甚至不需要测试它是字符串还是其他类型。
这是可能的,还是我在这里完全错过了一些东西?
I'm not sure whether it's called group typing, but what I mean is this:
Since PHP is dynamically typed, this adds delays which is understandable. Is it possible to create some kind of type system in PHP so that
ints,floats and other numeric values can be grouped under Number , as well as grouping of other types to increase runtime speeds so that if a variable is of type Number, at runtime, PHP can just quickly only check through that group without even testing if its a string or some other type.
Is this possible, or am I completely missing something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你错过了一些东西。数字和字符串不是 PHP 中的对象——它们是一种不同类型的值,已经或多或少按照您所描述的方式进行处理。
You're missing something. Numbers and strings aren't objects in PHP -- they're a distinct type of value, which is already handled more or less in the way that you describe.
在 PHP 中你根本无法做到这一点,该语言没有那种工具。
You simply can't do that in PHP, the language doesn't have that kind of tools.