Introduction of functions, declarations, return values and other features in php7
This article mainly introduces "the introduction of functions, declarations, return values and other features in php7". In daily operation, I believe many people have doubts about the introduction of functions, declarations, return values and other features in php7. I have consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer your doubts about the introduction of functions, declarations, return values and other features in php7. Next, please follow the editor to study!
Use. Operator defines variable length parameter functions (PHP 5 > = 5.6.0, PHP 7)
Now you can use... instead of relying on func_get_args (). Operator to implement a variable-length parameter function.
The above routine outputs:
$req: 1; $opt: 0; number of params: 0
$req: 1; $opt: 2; number of params: 0
$req: 1; $opt: 2; number of params: 1
$req: 1; $opt: 2; number of params: 2
$req: 1; $opt: 2; number of params: 3
Use. Operator for parameter expansion (PHP 5 > = 5.6.0, PHP 7)
When calling a function, use. Operator to expand arrays and traverable objects into function arguments. In other programming languages, such as Ruby, this is called the join operator.
The above routine outputs:
six
Use function and use const (PHP 5 > = 5.6.0, PHP 7)
The use operator has been extended to support importing external functions and constants into the class. The corresponding structures are use function and use const.
The above routine outputs:
forty-two
Name\ Space\ f
DebugInfo () (PHP 5 > = 5.6.0, PHP 7)
Add debugInfo (), which can be used to control the attributes and values to be output when you use var_dump () to output objects.
The above routine outputs:
Object (C) # 1 (1) {["propSquared"] = > int (1764)}
Scalar type declaration (PHP 7)
Scalar type declarations have two modes: mandatory (default) and strict. You can now use the following types of parameters (whether in mandatory mode or strict mode): string (string), integer (int), floating point number (float), and Boolean value (bool). They extend other types introduced in PHP5: class names, interfaces, arrays, and callback types.
Spaceship operator (combination comparator) (PHP 7)
The spaceship operator is used to compare two expressions. It returns-1, 0, or 1 respectively when $an is less than, equal to, or greater than $b. The principle of comparison is based on the general comparison rules of PHP.
Define a constant array through define () (PHP 7)
Constants of type Array can now be defined by define (). It can only be defined through const in PHP5.6.
At this point, the study of "introduction to functions, declarations, return values and other features in php7" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!