In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is const in php". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is const in php"?
Const in php is a keyword used to define a constant; when you use the const keyword to define a constant, you can only contain scalar data; you can define a constant as an expression or as an array.
The operating environment of this paper: Windows7 system, PHP7.1, Dell G3.
What does const mean in php?
Const in php is a keyword used to define a constant.
You can define a constant using either the const keyword or the define () function. The function define () allows you to define a constant as an expression, while the const keyword has some limitations, as shown in the following section. Once a constant is defined, it can no longer be changed or undefined.
When using the const keyword to define constants, you can only contain scalar data (bool, int, float, string). You can define a constant as either an expression or an array. Resource can also be defined as a constant, but should be avoided as much as possible, as it can cause unpredictable results.
You can simply get the value of a constant by specifying its name, and unlike variables, you should not precede a constant with a $sign. If the constant name is dynamic, you can also use the function constant () to get the value of the constant. You can get a list of all the defined constants with get_defined_constants ().
Note: constants and (global) variables are in different namespaces. This means that, for example, true and $TRUE are different.
If an undefined constant is used, an Error is thrown. Prior to PHP 8.0.0, calls to undefined constants were interpreted as a string of the constant, that is, (CONSTANT corresponds to "CONSTANT"). This method has been deprecated in PHP 7.2.0 and an E_WARNING level error is thrown. (an E_NOTICE-level error was issued before PHP 7.2.0. See why $Foo [bar] is wrong in the manual (unless bar is a constant). This does not apply to (fully) qualified constants and, if not defined, will always throw an Error.
Note: if you want to check whether a constant is defined, use the defined () function.
Constants and variables are different as follows:
The constant is not preceded by a dollar sign ($)
Constants can be defined and accessed anywhere regardless of the scope of the variable
Once a constant is defined, it cannot be redefined or undefined
Constants can only calculate scalar values or arrays.
Note:
In contrast to using define () to define constants, using the const keyword to define constants must be in the topmost scope, because this method is defined at compile time. This means that you cannot use const to define constants within functions, loops, or if or try/catch statements.
At this point, I believe you have a deeper understanding of "what is const in php". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.