[PHP] New Features of porting from PHP 5.6.x to PHP 7.0.x, 5.6.x7.0.x

Source: Internet
Author: User
Tags integer division

[PHP] New Features of porting from PHP 5.6.x to PHP 7.0.x, 5.6.x7.0.x

New features:

1. scalar type declaration

String (string), INTEGER (int), floating point number (float), Boolean (bool), callable, array, self, Class/interface name

2. Return Value Type Declaration

Define parameter type and Return Value Type

Function test (int $ a): int {}

If the parameter is not passed as required, an exception is returned.

3. null merge Operator

Null merge operator (??) , Equivalent to a ternary Operator

$ Name = $ _ GET ['name']? "Test"; echo $ name;

4. spacecraft operators (composite comparison operators)

If $ a is less than, equal to, or greater than $ B, it returns-1, 0, or 1.

$ A <=> $ B

5. define a constant array through define ()

Define ('animal', ['Dog', 'cat', 'bird']);

6. Anonymous class

A function parameter must be of the forced type, which is completed using an anonymous class.

Interface Logger {

Public function log (string $ msg );

}

Function test (Logger $ logger ){

Echo $ logger-> log ('aaa ');

}

Test (new Class implements Logger {

Public function log (string $ msg ){

Return $ msg;

}

});

7. Unicode codepoint translation syntax

The complete Unicode character is called codepoint. Unicode sets a unified and unique binary encoding for each character in each language.

8. Provides Filtering for unserialize (), provides a safer way to unpackage unreliable data, and prevents potential code injection through whitelist.

9. Expected, assert-check whether an asserted is FALSE

10. Group use declarations

Classes, functions, and constants imported from the same namespace can now be imported at one time using a single use statement.

11. The generator can return expressions.

12. Generator delegation

13. Integer Division function intdiv ()

14. session options

Session_start () can accept an array as the parameter to overwrite the settings in the php. ini file.

15. CSPRNG Functions

Random_bytes () and random_int () are used to generate high-security random strings and random integers.

16. You can use the list () function to expand the objects that implement the ArrayAccess interface.

17. Other features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.