php - 定义全局常量的最佳方法(可在所有文件中使用) [英] php - Best way to define Global Constant (available in all files)

查看:408
本文介绍了php - 定义全局常量的最佳方法(可在所有文件中使用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

定义一个常量的最佳方式是全局的,即应该在PHP中的所有文件中都可用。

谢谢

更新:常量和类常量之间有什么区别,它们可以交替使用吗?

>在您的 top .php文件中定义常量,该文件将包含在所有其他脚本中。它可能是您的前端控制器,您的配置文件或为此目的而创建的文件。

  define('MY_CONST', '你好'); 


What is the best way to define a constant that is Global i.e should be available in all the files in PHP.

Thanks

UPDATE: What are the differences between the constants and Class constants, can they be used interchangeably ?

解决方案

Define your constant in your top .php file, that will be included in all the other scripts. It may be your front controller, your config file, or a file created for this single purpose.

define('MY_CONST', 'hello');

这篇关于php - 定义全局常量的最佳方法(可在所有文件中使用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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