/PHP7

A Peek at PHP 7 - Helped in the preparation of slides for the presentation at Devcon MRU 2016 by Pierre-Alexandre Clorichel

#A peek at PHP 7

  1. Slide 1:
  • Release of PHP 7: 3 December 2015
  • PHP 7 is now powered by PHPNG (the Next Generation of Zend Engine)
  1. Slide 2:

    Why PHP 7?

    One Word: PERFORMANCE

  2. Slide 3:

  • Insert Images here to show benchmarking results for:

    • Magento

    • WordPress

    • ZF

    • Laravel

  1. Slide 4:
Incompatibilities:
  • Deletion of deprecated functionalities:

Deprecated extensions

  1. Slide 5:
Incompatibilities:
<?php
class ItWasTime{
	public function ItWasTime(){...}
}

new ItWasTime();
  1. Slide 6:
Incompatibilities:

Deprecated extensions

  1. Slide 7:
Incompatibilities:
  • Deletion of ASP and script tags

Deprecated extensions

  1. Slide 8:
Incompatibilities:
  • 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.

Deprecated extensions

  1. Slide 9:
Incompatibilities:

An invalid octal now throws a fatal error.

Deprecated extensions

  1. Slide 10:
Incompatibilities:

Hexadecimal values are no longer recognized as numeric values. Deprecated extensions

  1. Slide 11:
Incompatibilities:

Deprecated extensions

  1. Slide 12:
Incompatibilities:

The two functions func_get_arg and func_get_args returns the value of the variable in their local context.

Deprecated extensions

  1. 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.

Deprecated extensions

  1. Slide 14:
  • Possibility to define the type of the returned value. A catchable fatal error is returned if it do not correspond.

Deprecated extensions

  1. Slide 15:

Group use declaration

  • Commmon namespace declaration can be grouped.

Deprecated extensions

  1. Slide 16:
  • Anonymous Class
  • Same principle as for Anonymous function.

Deprecated extensions

  1. 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

Deprecated extensions

Deprecated extensions

  1. 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.

Deprecated extensions