Home  >  Article  >  Backend Development  >  Why can PHP constants be defined as expressions whose values ​​change?

Why can PHP constants be defined as expressions whose values ​​change?

WBOY
WBOYOriginal
2016-10-10 11:55:561043browse

The official PHP manual says, "Once a constant is defined, it cannot be changed or undefined."

But why can this kind of value change be defined in the program?

<code>define("MESSAGE", time());

//输出常量
echo MESSAGE;</code>

Reply content:

The official PHP manual says, "Once a constant is defined, it cannot be changed or undefined."

But why can this kind of value change be defined in the program?

<code>define("MESSAGE", time());

//输出常量
echo MESSAGE;</code>

From a grammatical point of view, this is not wrong. The changes mentioned in the manual emphasize the later human changes, including cancellation.

The MESSAGE you want to express here is variable, which can be understood as the result of PHP itself finding time() in the memory during operation.

I guess, this should have something to do with functional programming. The time() function can be assigned to a constant. Accessing the constant is equivalent to accessing the time() function, and the return value of the time() function is constantly changing.

Once a constant is defined, it cannot be changed or undefined

Then you can try changing MESSAGE,
For example, MESSAGE += 1;

It feels like this is establishing a connection to the time() function!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn