PHP7 - PHPLimBe

PHP7 - PHPLimBe

Talk about php7 presented at php limburg BE.

35617c1bde6460e06755ffada7d55ee8?s=128

Bart Van den Brande

October 29, 2015
Tweet

Transcript

  1. 1.
  2. 4.

    Variable-length argument lists … and unpacking function sum(...$numbers) { $acc

    = 0; foreach ($numbers as $n) { $acc += $n; } return $acc; } echo sum(1, 2, 3, 4);
  3. 5.

    Scalar const() modifactions const ONE = 5; const TWO =

    ONE * 2; // You can even use arrays const THREE = [1, 2];
  4. 6.

    Exponentiation ** 2 ** 3 = 8 2 ** 3

    ** 2 == ?; ‘use’ function and ‘use’ const use const Name\Space\FOO; use function Name\Space\f;
  5. 12.
  6. 13.
  7. 15.
  8. 16.

    Loosen things up // 'new', 'private', and 'for' were previously

    unusable Project::new('Project Name’)->private() ->for('purpose here’) ->with('username here'); Relax
  9. 17.

    New reserved words - int - float - bool -

    string - true - false - null - resource - object - mixed - numeric
  10. 18.

    Take it eaaaasy … JSON Extension Replaced with JSOND PHP4

    Constructor deprecated in favour of __construct() Removal of date.timezone Warning Removal of Alternative PHP Tags Removal of Multiple Default Blocks in Switch Statements Removal of Deprecated Functionality
  11. 21.

    Returns a integer 1 - left hand operator 0 -

    equal -1 - right hand operator RFC: Combined Comparison Operator Able to compare - strings - numbers - arrays var_dump(123 <=> 456); // int(-1)
  12. 23.

    RFC: Null Coalesce Operator $route = $_GET['route'] ?? 'index'; $route

    = isset($_GET['route']) ? $_GET['route'] : 'index'; = isset() shorthand
  13. 25.

    RFC: basic scalar types function sumOfInts(int ...$ints) { return array_sum($ints);

    } var_dump(sumOfInts(2, '3', 4.1)); // int(9) Coercive mode
  14. 26.

    function add(int $x, int $y) { return $x + $y;

    } var_dump(add(2, 4)); // int(6) Strict mode declare(strict_types=1); RFC: basic scalar types
  15. 32.

    use some\namespace\ {ClassA, ClassB, ClassC as C}; use some\namespace\ClassA; use

    some\namespace\ClassB; use some\namespace\ClassC as C; Becomes
  16. 33.

    interface Throwable |- Exception class implements Throwable |- ... |-

    Error class implements Throwable |- TypeError extends Error |- ParseError extends Error |- AssertionError extends Error |- ArithmeticError extends Error |- DivisionByZeroError extends ArithmeticError Exceptions
  17. 34.

    Exceptions try { // Code that may throw an error

    } catch (Exception $e) { // Handle exception } catch (Error $e) { // Handle error }