Home > Backend Development > PHP Tutorial > Introduction to PHP language constructors_PHP tutorial

Introduction to PHP language constructors_PHP tutorial

WBOY
Release: 2016-07-21 15:00:33
Original
843 people have browsed it

There are several special keywords in PHP such as echo, print, die, require, etc. Although they look like functions, they are actually more similar to control statements such as if and while, rather than a function. That is, when the interpreter encounters:

Copy code The code is as follows:

print 'Hello world';


When such an expression is generated, it is not converted into a function call, but is directly mapped to a series of predefined operations. You can add parentheses or not when using language constructs, but you must add parentheses when using functions.

The "variable function" you mentioned is "variable function" in English. The meaning of variable function is a bit distorted when translated into "variable function". The noun variable (variable) is used as an adjective (variable). ) to translate the meaning. Variable function in PHP means that if you add a pair of parentheses after a variable, the interpreter will try to find a function with the same name as the value of the variable, and execute it if it is found. For example, there is a function foo(), then you can call this function in the following way:

Copy code The code is as follows:

//Initialize a string variable
$func = 'foo';

// Find the function with the same name as this string and execute it
$func();

So, the meaning of the sentence you mentioned is that it is not allowed to use variable functions to call a language construct, such as the following:

Copy code The code is as follows:

$func = 'print';

// This will An exception is generated because print is not a function, but a component of the language
$func('hello world');

Executing this code will generate an exception because the function print is not defined.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328055.htmlTechArticleThere are several special keywords in PHP such as echo, print, die, require, etc. Although they are used like Function, but it is actually more similar to control statements such as if and while, rather than a function. ...
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