What is the role of define in addition to defining constants?

Source: Internet
Author: User
What is the role of define in addition to defining constants? Can I change the definition of a constant? Why have the APP been defined so many times? The constant value seems to be a path. Shouldn't it be a defined constant?
Define ("APP", "./admin"); what is the role of this sentence?


Reply to discussion (solution)

Define defines constants. constants can be numbers or strings .. When you echo the APP;, the output is./admin. Similar to defining variables

After a constant is set, its value cannot be changed. Define ("APP", "./admin");, not a constant, defines the compilation Directory, that is, the app scope is under admin.

A constant is the identifier (name) of a single value ). This value cannot be changed in the script.

Define is to define constants. any content can be used as long as the values comply with the syntax rules.
Define ("APP", "./admin"); defines a constant APP whose value is./admin.
To use an APP, use./admin.

Similar definitions are available in multiple files because your files are not executed simultaneously (during an HTTP session ).
When index. php is executed, the APP is./home.
When admin. php is executed, the APP is./admin.
When wap. php is executed, the APP is./wap
In this way, you don't have to differentiate the directory in which the program actually works.

A common usage is to restrict files to access from a certain file (such as a bootstrap file). This common mode is:
If (! Defined ("XXXX") exit;

That's how it works. nothing else.
Defined and define are different methods.

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.