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

问题描述

我当前的Web应用程序使用大约30个左右的Contant(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.

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

08-22 18:24