Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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. None
  2. @denbatte

  3. I know what you did last … version PHP5.6

  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);
  5. Scalar const() modifactions const ONE = 5; const TWO =

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

    ** 2 == ?; ‘use’ function and ‘use’ const use const Name\Space\FOO; use function Name\Space\f;
  7. Large file uploads php://input is reusable phpdbg Default character encoding

    SSL/TLS improvements …
  8. Skipping number 6

  9. Mid November 2015 When will 7 be released?

  10. PHP7 Some new features

  11. Speed improvements Tests by Rasmus Lerdorf http://talks.php.net/fluent15#/ More performance -

    less memory usage Thanks to the PHPNG project
  12. None
  13. None
  14. New or improved functions

  15. intdiv() var_dump(intdiv(10, 3)); // int(3) session_start() session_start(['cache_limiter' => 'private']); define()

    define( 'ALLOWED_IMAGE_EXTENSIONS', ['jpg', 'jpeg', 'gif', ‘png'] );
  16. Loosen things up // 'new', 'private', and 'for' were previously

    unusable Project::new('Project Name’)->private() ->for('purpose here’) ->with('username here'); Relax
  17. New reserved words - int - float - bool -

    string - true - false - null - resource - object - mixed - numeric
  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
  19. New and shiny

  20. Combined Comparison Operator Space <=> ship

  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)
  22. Null Coalesce Operator Say what ??

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

    = isset($_GET['route']) ? $_GET['route'] : 'index'; = isset() shorthand
  24. Scalar Type Declarations coercive and strict

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

    } var_dump(sumOfInts(2, '3', 4.1)); // int(9) Coercive mode
  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
  27. Return Type Declarations Know what you get RFC: Return Type

    Declarations
  28. function sumOfInts(int …$ints): array { return array_sum($ints); } Return Type

    Declarations RFC: Return Type Declarations
  29. Anonymous Classes Hidden in the code RFC: Anonymous Classes

  30. $util->setLogger(new class { public function log($msg) { echo $msg; }

    }); RFC: Anonymous Classes
  31. Group use Declarations Lets use them! RFC: Group use Declarations

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

    some\namespace\ClassB; use some\namespace\ClassC as C; Becomes
  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
  34. Exceptions try { // Code that may throw an error

    } catch (Exception $e) { // Handle exception } catch (Error $e) { // Handle error }
  35. https://github.com/rlerdorf/php7dev Testing PHP7 Vagrant box

  36. References! https://github.com/tpunt/PHP7-Reference/blob/master/README.md https://wiki.php.net/rfc https://github.com/gophp7/gophp7-ext/wiki/extensions-catalog http://gophp7.org/gophp7-ext/extensions-catalog.html http://php.net/manual/en/migration56.new-features.php

  37. Questions?

  38. Joindin https://joind.in/talk/view/16058 Feedback