Home > Backend Development > PHP Tutorial > The difference between PHP language structures and functions

The difference between PHP language structures and functions

巴扎黑
Release: 2016-11-23 09:35:26
Original
1125 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 ($ user)) {

// do some things

}

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

So what is 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 exist 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 of parsers than language structures. parse. In this way, you 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 reprocessing links. Language structures cannot be used in configuration items ( 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(), note, include_once() is the function

require(). Note that require_once() is the function

array()

list()

empty()

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