开发者

How PHP macro define is interpreted?

开发者 https://www.devze.com 2023-03-16 17:37 出处:网络
For C/C++, I think the Preprocessor does the Macro processing before compiler compiles the program and that\'s why Macro name has to be literal or absolute, no variable allowed to declared Macro name.

For C/C++, I think the Preprocessor does the Macro processing before compiler compiles the program and that's why Macro name has to be literal or absolute, no variable allowed to declared Macro name.

In case of PHP, we can declare like this: DEFINE($name, $value); Which means, interpreter first interprets the variable and then macro is defined, i.e. like runtime macro processing.

Which actually creates a doubt that, is that really macro processing ? If not then what's the purpose of introducing such keyword like 'define'; to have values which cannot be changed ?

开发者_运维问答Or if there's macro processing, then can anybody explain, how it could be working ?


For the sake of completeness, there is a constant that is defined at compile-time :

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.

This is for the current PHP Version, 5.3.


Define() declares a constant. In PHP you cannot declare a macro like in C and generally there is no need to.

For more info try the excelent php website


PHP is an interpreted language - we can not talk about compilation in PHPs case. DEFINE is used for defining constants - PI for example


http://php.net/manual/en/function.define.php

Defines a named constant at runtime.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号