#A peek at PHP 7
- Slide 1:
- Release of PHP 7: 3 December 2015
- PHP 7 is now powered by PHPNG (the Next Generation of Zend Engine)
-
Slide 2:
Why PHP 7?
One Word: PERFORMANCE
-
Slide 3:
-
Insert Images here to show benchmarking results for:
-
Magento
-
WordPress
-
ZF
-
Laravel
-
- Slide 4:
- Slide 5:
<?php
class ItWasTime{
public function ItWasTime(){...}
}
new ItWasTime();
- Slide 6:
- Slide 7:
- Deletion of ASP and script tags
- Slide 8:
-
Switch case no longer accept multiple defaults. It should contain only one otherwise you will get a Fatal error.
-
Causes fatal error: Switch statements may contain one default clause.
- Slide 9:
An invalid octal now throws a fatal error.
- Slide 10:
Hexadecimal values are no longer recognized as numeric values.
- Slide 11:
- Slide 12:
The two functions func_get_arg
and func_get_args
returns the value of the variable in their local context.
- Slide 13:
- Scalar type hinting -- PHP 7 offer you the possibility to type hint with string, integer, float, boolean.
Activate by adding declare(strict_types=1);
at the top.
- Slide 14:
- Possibility to define the type of the returned value. A catchable fatal error is returned if it do not correspond.
- Slide 15:
Group use declaration
- Commmon namespace declaration can be grouped.
- Slide 16:
- Anonymous Class
- Same principle as for Anonymous function.
- Slide 17:
Spaceship Operator
-
A new comparison operator (Combined Comparison Operator)
-
It is identical to functions strcmp() et version_compare()
-
But can compare all types as long as the type on the left is the same as on the right.
-
It can compare numbers, strings, arrays, objects, ...
Returns:
- 0 if equal
- -1 if the value on the left is less
- 1 if the value on the right is less
- Slide 18:
The Null Coalesce Operator
- Returns the result of the left operation if it is not NULL else it returns the results of the right operation.