哪个更快?常量、变量或变量数组 [英] Which is faster? Constants, Variables or Variable Arrays

查看:24
本文介绍了哪个更快?常量、变量或变量数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的 Web 应用程序使用了大约 30 个左右的内容 (DEFINE()).我正在阅读变量更快的东西.假设有一个命名约定来避免变量覆盖,我看到的唯一另一个缺点是这些变量必须在每个函数中以某种方式定义为全局变量.

My current web application uses about 30 or so Contants (DEFINE()). I am reading things that variables are quicker. Provided that there is a naming convention to avoid variable overwrites, the only other draw back I see is that these variables would have to be defined as global variables some how in every function.

哪个更快?我在整个应用程序中大量使用这些常量,并且可能会永远向列表中添加更多常量,并且它们被用于函数和类的内部和外部.

Which is faster? I use these constants a whole lot throughout my application and will probably be forever adding more to the list and they are used in and out of functions and classes.

推荐答案

使用 define() 定义的常量在 PHP 中相当慢.人们实际上编写了扩展程序(如 hidef)来提高性能.

Constants defined using define() are fairly slow in PHP. People actually wrote extensions (like hidef) to improve the performance.

但除非你有大量的常量,否则这应该没有太大区别.

But unless you have loads of constants this shouldn't make much of a difference.

从 PHP 5.3 开始,您还可以使用 const NAME = VALUE; 来使用编译时常量.这些速度要快得多.

As of PHP 5.3 you can also use compile-time constants using const NAME = VALUE;. Those are much faster.

这篇关于哪个更快?常量、变量或变量数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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