Php7 new features


1. Scalar type declaration
There are two modes: mandatory (default) and strict. You can now use the following type parameters (whether in forced or strict mode): string (string), integer (int), float (float), and Boolean (bool). They extend other types introduced in PHP5: class names, interfaces, arrays, and callback types. In the old version, the parameter declaration of a function can only be array classname, and basic types such as int and string cannot be declared
2. Return value type declaration
Php7 adds support for return type declaration, which indicates the type of function return value. The available types are the same as those available in the parameter declaration
3. Null merge operator
There are a large number of cases in the project where ternary expressions and isset are used at the same time. A new null merge operator (?) is added This grammar sugar. If the variable exists and the value is not null, it will return its own value; otherwise, it will return its second operand.
4. Spacecraft operator (combination comparator)
The spacecraft operator is used to compare two expressions. When $a is less than, equal to, or greater than $b, it returns -1,0,1, respectively. The comparison principle is to follow the regular comparison rules of PHP$ a<=>$b
5. Define constant array through define
6. Anonymous class
Now it supports instantiating an anonymous class through new class, which can be used to replace some complete class definitions of “burn after use”
7. Unicode codepoint translation syntax
This receives a Unicode codepoint in hexadecimal form and prints a string in utf8 encoding format surrounded by double quotation marks or heredoc. Any valid codepoint can be received, and the first 0 can be omitted.

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Recommended Today

App cold start optimization: how to use good tools [perfetto\ systrace \methodtracing]

Lifelong learning with you, here is the programmer Android Classic good articles are recommended. By reading this article, you will gain the following knowledge points: 1、 Definition of cold start and points that can be optimized2、 How to locate current performance problems3、 Perfetto/systrace: overall situation and scheduling4、 For the overall cold start optimization effect: it […]