Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the new features of all versions of php7

Shulou Source: shulou.com Published: 2022-06-03 10:53:49 11月15日 Update

What are the new features of all versions of php7? many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

New features of each version of php7 summarize the new features of PHP7.1 1. Nullable (Nullable) type

The type of the parameter and the return value can now be allowed to be empty by putting a question mark before the type. When this feature is enabled, the result returned by the passed parameter or function is either a given type or null

# php5function ($a = null) {if ($a===null) {return null;} return $a;} # php7+function fun ():? string {return null;} function fun1 (? $a) {var_dump ($a);} fun1 (null); / / nullfun1 ('1'); / / 12. Void type

The method that returns the value declared as void can either omit the return statement altogether. NULL is not a legal return value for void.

Function fun (): void {echo "hello world";} 3. Class constant visibility class Something {const PUBLIC_CONST_A = 1; public const PUBLIC_CONST_B = 2; protected const PROTECTED_CONST = 3; private const PRIVATE_CONST = 4;} 4. Iterable pseudo-class

This can be used in parameters or return value types, which represent objects that accept arrays or implement the Traversable interface.

Function iterator (iterable $iter) {foreach ($iter as $val) {/ /} 5. Multiple exception capture processing

A catch statement block can now capture multiple exceptions through the pipe character (_ | _). This is useful when you need to handle different exceptions from different classes at the same time.

Try {/ / some code} catch (FirstException | SecondException $e) {/ / handle first and second exceptions} 6. List supports key name $data = [["id" = > 1, "name" = > 'Tom'], ["id" = > 2, "name" = >' Fred'],]; / / list () stylelist ("id" = > $id1, "name" = > $name1) = $data [0]; var_dump ($id1); / / 17. The string supports negative $a = "hello"; $a [- 2]; / / l8. Convert callback to closure

Closure has added a static method to quickly convert callable into a Closure object.

Tags: Support type function character parameter string property constant method syntax content object version size comma element memory attribute array or Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker MariaDB macOS Apple