Why can PHP constants be defined as expressions with variable values?

Source: Internet
Author: User
In the official php Manual, "once a constant is defined, it cannot be changed or undefined ". But why can this value change form be defined in the program? In the official php Manual {code...}, "once a constant is defined, it cannot be changed or undefined ".

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

Define ("MESSAGE", time (); // returns the constant echo MESSAGE;

Reply content:

In the official php Manual, "once a constant is defined, it cannot be changed or undefined ".

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

Define ("MESSAGE", time (); // returns the constant echo MESSAGE;

In terms of syntax, there is no error. the changes mentioned in the manual emphasize human changes in the future, including cancellation.

Here, the MESSAGE you want to express is variable. it can be understood that php finds the time () result in the memory during running.

I guess this should be related to functional programming. The time () function can be assigned to a constant. accessing a 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 to change the MESSAGE,
For example, MESSAGE + = 1;

It seems that this is a function connected to time!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.