The difference between PHP language constructs and functions

巴扎黑
Release: 2016-11-23 13:28:43
Original
1517 people have browsed it

I believe you often see comparisons in some PHP applications, saying that isset() is used to replace strlen(), and isset executes faster than strlen. F Example: (if (iSSET ($ username [5])) {

// The username is at Least Six Character Long.

}

The reason is that the isset is a language structure, and Strlen is a function. So what are language structures? Is it any different from a function?

1. What are language structures and functions

Language structure: It is the keyword of the PHP language and part of the language grammar; it cannot be defined by the user or added to a language extension or library; it can have or There can be no variables and return values.

Function: It is composed of code blocks and can be reused.

2. Why are language structures faster than functions? The reason is that in PHP, functions are first decomposed into language structures by the PHP parser, so it can be seen that functions have one more layer of parser analysis than language structures. In this way, we can better understand

which language structures are faster than functions.

3. The difference between language structures and functions

Language structures are faster than corresponding functions

Language structures are more robust in error handling. Since they are language keywords, they do not have to be reprocessed

Language structures cannot be disabled in configuration items (php.ini), but functions can.

                                                                                                                                                Through out die()

isset() : Only used for variables

                                                                       ’ s ’ s ’ s ’ s ’ s           ‐ ‐ ‐‐‐‐‐ into to the list to be used for variables

​ ​ ​ ​()

empty(): only used for variables

In the following situations, isset() returns TRUE:

$var = "";

$var = array();

$var = 0;

$var = false;

So far: only if null or no value is assigned, it will not pass. It is recommended to use empty

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