Find your content:

Search form

You are here

PHP7 vs PHP5

 
Share

PHP7 vs PHP5

Why PHP7?

1. Performance

2. Spaceship Operator

3. Return type declaration

4. Null Coalesce Operator

before

if (isset ($_GET [‘name’]))
   {
        $name = $_GET [‘name’];
   }
   else
        $name = null;

now
$name = $_GET [‘name’]?? Null;


5. Less memory allocation
PHP5 occupies more memory for the arrays due to the internal structure of the language. It is improved in PHP7. Lets take a example

To measure memory utilization I am using the following script, which tests the creation of an array with 100000 distinct integers:
$startMemory = memory_get_usage();
$array = range(1, 100000);
echo memory_get_usage() - $startMemory, " bytes\n";

The following table shows the results using PHP 5.6 and PHP 7 on 32bit and 64bit systems:

        |   32 bit |    64 bit
------------------------------
PHP 5.6 | 7.37 MiB | 13.97 MiB
------------------------------
PHP 7.0 | 3.00 MiB |  4.00 MiB


Typically hashtables are not explicitly ordered,If you iterate over a PHP array you will get back the elements in the exact order in which they were inserted. This means that PHP’s hashtable implementation has to support an additional mechanism for remembering the order of array elements.



My Block Status

My Block Content