Introduction to PHP 7 new features Introduction

Source: Internet
Author: User
Tags benchmark scalar


The performance breakthrough in PHP 7 has become one of the hottest topics in recent times, and currently the official PHP 7.0.0 Beta 2 has been released
New features
Performance Improvement: PHP 7 is twice times faster than PHP 5.6
Full and consistent 64-bit support
Removed some old unsupported sapi (server-side application programming ports) and extensions
Added the null engagement operator (??) "Wiki"

$username = $_get[' user ']?? ' Nobody ';
Equivalent to: $username = isset ($_get[' user '))? $_get[' user ']: ' nobody ';

New added 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 return type of function declares "wiki"

function foo (): array {
return [];
}

New scalar type declaration "wiki" added

The main function of scalar declarations is to automatically implement mandatory type conversions of parameters
Variable type declarations (int, float, string, bool)
function add (int $a, int $b): int {
return $a + $b;
}

New Add anonymous class "wiki"

Class Foo {}
$child = new class extends Foo {};
Var_dump ($child instanceof Foo); True

Fatal errors can be caught, and older versions can only be processed after 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, $a);
}

The test results are as follows

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


Benchmark results in the community:


To WordPress Open Source Blog Home page for testing the test results:

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.