PHP_Const, constphp_PHP tutorial
PHP_Const, constphp
PHP_Const
Constant rules:
1 is always uppercase
2 A-Z and ASCII characters from 127 to 255
3 Global scope
4 Define with define function
5 Can only contain scalar data such as Boolean integer float string
6 Do not add dollar sign in front
PHP comes with constants = special constants
Case-insensitive
_LINE_ Current line number in the file
_FILE_ Full path to the file File name
_FUNCTION_ Function name
_CLASS_ Class name
_METHOD_ Class method name
_LINE_
php script line number. If a file is referenced, the constant in the referenced file is the line of the referenced file
rather than the line of the referenced file, that is, downwards The principle of passing
_FILE_
is the same as above
define part:
Macros can be used not only to replace constant values, but also to replace expressions and even code segments.
(Macros are very powerful, but they are also error-prone, so their pros and cons are quite controversial.)
The syntax of macro is:
#define Macro name and macro value
As a suggestion and a common habit among programmers, macro Names often use all capital letters.
Advantages of using macros:
1) Make the code more concise and clear
Of course, this depends on how you set the macro Pick an appropriate name. Generally speaking, macro names should have clear and intuitive meanings, and sometimes it is better to make them longer.
2) Facilitate code maintenance
The processing of macros is called "preprocessing" during the compilation process.
That is to say, before formal compilation, the compiler must first replace the macros that appear in the code with their corresponding macro values. This process is a bit like the search and replace that you and I use in word processing software. Therefore, when macros are used to express constants in the code, in the final analysis, immediate numbers are used, and the type of this quantity is not clearly specified.
const part
The format of constant definition is:
const data type constant name = constant value;
A constant must be assigned a value at the beginning. Then, in subsequent code, we are not allowed to change the value of this constant.
The difference between the two:
1 On the allocation of memory space .
defineWhen defining a macro, no memory space will be allocated. It will be replaced in the main function during compilation. It is just a simple replacement without any checking.
For example, type, statement structure, etc., that is, macro-defined constants are just pure placement relationships, such as #define null 0;
When the compiler encounters null, it always replaces null with 0. It has no data type (if you have any questions, please look at the preprocessing part of the C language book or look at MSDN.
The constant defined by const has a data type,
Defining constants of data types facilitates the compiler to check the data and troubleshoot possible errors in the program,
So the difference between const and define is
Defining constants as const eliminates the unsafety between programs.
Define global constants that can be accessed anywhere
const is used for class member variable definition. It can only be accessed using the class name and cannot be changed. If you are a beginner, just understand it first and don’t get too carried away.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Detailed explanation and code examples of const in C In C language, the const keyword is used to define constants, which means that the value of the variable cannot be modified during program execution. The const keyword can be used to modify variables, function parameters, and function return values. This article will provide a detailed analysis of the use of the const keyword in C language and provide specific code examples. const modified variable When const is used to modify a variable, it means that the variable is a read-only variable and cannot be modified once it is assigned a value. For example: constint

This article brings you relevant knowledge about JavaScript. It mainly introduces the differences between var, let and const, as well as the relationship between ECMAScript and JavaScript. Interested friends can take a look at it. I hope Helpful to everyone.

const is a keyword that can be used to declare constants, const modifiers in function parameters, const modified function return values, and const modified pointers. Detailed introduction: 1. Declare constants. The const keyword can be used to declare constants. The value of the constant cannot be modified during the running of the program. The constant can be a basic data type, such as integer, floating point number, character, etc., or a custom data type; 2. The const modifier in the function parameters. The const keyword can be used in the parameters of the function, indicating that the parameter cannot be modified inside the function, etc.

Audio output and input require specific drivers and services to work as expected on Windows 11. These sometimes end up running into errors in the background, causing audio issues like no audio output, missing audio devices, distorted audio, etc. How to Fix Audio Service Not Responding on Windows 11 We recommend you to start with the fixes mentioned below and work your way through the list until you manage to resolve your issue. The audio service may become unresponsive for a number of reasons on Windows 11. This list will help you verify and fix most issues that prevent audio services from responding on Windows 11. Please follow the relevant sections below to help you through the process. Method 1: Restart the audio service. You may encounter

Correct usage of the const keyword in C++: Using const to modify a function means that the function will not modify the parameters or class members passed in. Using const to declare a function pointer means that the pointer points to a constant function.

For C++ programmers, syntax errors are one of the most common problems. One of the common mistakes is that const objects must be initialized at definition time. If you encounter this situation, how should you deal with it? First, we need to understand what a const object is. The const keyword is a special type qualifier in C++ that specifies that the value of a variable cannot be changed during the execution of the program. Such variables are called "constants". If you define a const object without initializing it, you will encounter the above error. This is

As a strongly typed language, C++ needs to consider many details when performing type conversion. A common problem is that const objects cannot be converted into non-const objects. This problem is more common when pointers and references are involved. Next, we will detail the causes and solutions to this problem. The cause of the problem is that the const keyword in C++ is used to define constants. Once a constant is defined, it cannot be modified. When we convert a const object to a non-const object, we are actually trying to modify a

C++ syntax error: const-modified member functions must declare const members, how to deal with it? In the C++ language, const is a very important keyword, which is used to modify certain variables, pointers, member functions, etc. For member functions, if it is modified with the const keyword, the value of the member variable cannot be modified inside the function body. However, if we do not add the const keyword in both the function declaration and definition, we will encounter a compilation error "The const-modified member function must be declared
