PHP 7 new features-PHP source code

Source: Internet
Author: User
What are the new features of PHP 7? The new features of PHP7 mainly improve the performance. We can achieve the acceleration performance without using the php acceleration plug-in as long as php 7 is used. Is that true? Let's take a look at the new features of PHP 7. What are the new features of PHP 7? The new features of PHP 7 mainly improve the performance. We can achieve the acceleration performance without using the php acceleration plug-in as long as PHP 7 is used. Is that true? Let's take a look at the new features of PHP 7.

Script ec (2); script


PHP 7's performance breakthrough has become one of the hottest topics recently. The official PHP 7.0.0 Beta 2 has been released.
New Features
Performance Improvement: PHP 7 is twice faster than PHP 5.6
Fully consistent 64-bit support
Removed some old unsupported SAPI (server-side application programming port) and extensions
Added the null join operator (??) [Wiki]

$ Username = $ _ GET ['user']? 'Nobody ';
// Equivalent to: $ username = isset ($ _ GET ['user'])? $ _ GET ['user']: 'nobody ';

Added the combined comparison operator (<=>) [wiki]

$ A = 1;
$ B = 2;

Switch ($ a <=> $ B)
{
Case 1:
Echo "a> B ";
Break;
Case 0:
Echo "a = B ";
Break;
Case-1:
Echo "a <B ";
Break;
}

Newly Added function return type declaration [wiki]

Function foo (): array {
Return [];
}

A scalar type declaration [wiki] is added]

// The main function of scalar declaration is to automatically implement forced type conversion of parameters.
// Variable type declaration (int, float, string, bool)
Function add (int $ a, int $ B): int {
Return $ a + $ B;
}

New Anonymous class [wiki]

Class Foo {}
$ Child = new class extends Foo {};
Var_dump ($ child instanceof Foo); // true

Fatal errors can be captured. Earlier versions can only be post-processed through register_shutdown_function. (Wiki)

Benchmark
Test code:
$ Count = $ argv [1];

$ A = array ();
For ($ I = 0; $ I <$ count; $ I ++ ){
$ A [$ I] = $ I;
}

Foreach ($ a as $ I ){
Array_key_exists ($ I, $ );
}

The test results are as follows:

It can be seen that PHP 7 is more than several times faster than PHP 5.4.


Benchmark Results in the community:


Test results of the test scenario on the WordPress open source blog homepage:

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.