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

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

WBOY
Release: 2016-10-10 11:55:56
Original
1124 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template