在PHP中定义与变量 [英] DEFINE vs Variable in PHP

查看:84
本文介绍了在PHP中定义与变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释使用之间的区别

Can someone explain the difference between using

define('SOMETHING', true);

$SOMETHING = true;

也许彼此之间有好处?

我到处都使用变量,甚至在每个页面都包含的配置类型文件中,我仍然使用变量,因为我不明白为什么要使用define方法.

I use variables everywhere and even in a config type file that is included to everypage I still use variables as I don't see why to use the define method.

推荐答案

DEFINE创建一个常数,该常数是全局的,可以在任何地方使用.它们也不能重新定义,可以是哪个变量.

DEFINE makes a constant, and constants are global and can be used anywhere. They also cannot be redefined, which variables can be.

我通常对配置使用DEFINE,因为事后没有人可以弄乱它,而且我可以在没有全局关联的情况下在任何地方对其进行检查,从而使检查更加容易.

I normally use DEFINE for Configs because no one can mess with it after the fact, and I can check it anywhere without global-ling, making for easier checks.

这篇关于在PHP中定义与变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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