Home > Backend Development > PHP Tutorial > Sharing examples of the differences between PHP language structures and functions

Sharing examples of the differences between PHP language structures and functions

小云云
Release: 2023-03-21 13:50:02
Original
1155 people have browsed it

I believe you often see comparisons in some PHP applications, saying that isset() is used to replace strlen(), isset executes faster than strlen, etc. This article mainly shares with you examples of the differences between PHP language structures and functions. I hope it can help. Everyone.

Example:

 if ( isset($user) ) { 
                //do some thing 
}
Copy after login

The reason is that isset is a language structure, and strlen is a function. Also, echo is a language structure, not a function.

So what is a language structure? 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 language extensions or libraries; It may or may not have variables and return values.

Function: It is composed of code blocks and can be reused. From the perspective of source code, it is implemented based on the Zend engine. The functions in the ext extension library are implemented in this way.

2. The reason why language structures are faster than functions is that in PHP, functions are first decomposed into language structures by the PHP parser (Zend engine), so it can be seen that functions have one more layer than language structures. Parser parsing. In this way, you can better understand which language structures are faster than functions.

3. The difference between language structures and functions. The language structure is faster than the function of the corresponding function. The language structure is more robust in error handling. Since it is a language keyword, it does not have the link of reprocessing. The language structure cannot be configured It is disabled in the item (php.ini), but the function can. Language structures cannot be used as callback functions

4. List of language structures

echo()
print()
die()
isset()
unset()
include(),注意,include_once()是函数
require(),注意,require_once()是函数
array()
list()
empty()
Copy after login

Related recommendations:

The difference between PHP language structures and functions

The above is the detailed content of Sharing examples of the differences between PHP language structures and functions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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