gpt4 book ai didi

php - 如何解释 PHP 宏定义?

转载 作者:行者123 更新时间:2023-12-04 13:50:14 24 4
gpt4 key购买 nike

对于 C/C++,我认为预处理器在编译器编译程序之前进行宏处理,这就是为什么宏名称必须是文字或绝对名称,不允许声明宏名称的变量。

对于 PHP,我们可以这样声明:DEFINE($name, $value);也就是说,解释器首先解释变量,然后定义宏,即像运行时宏处理。

这实际上让人怀疑,这真的是宏处理吗?如果不是那么引入像'define'这样的关键字的目的是什么?具有无法更改的值?

或者如果有宏处理,那么谁能解释一下它是如何工作的?

最佳答案

为了完整起见,一个在编译时定义的常量:

const MY_CONSTANT = 'something';

As opposed to defining constants using define(), constants defined using the const keyword must be declared at the top-level scope because they are defined at compile-time. This means that they cannot be declared inside functions, loops or if statements.

From the PHP Manual .

这是针对当前的 PHP 版本 5.3。

关于php - 如何解释 PHP 宏定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6555775/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com