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

The new features of PHP 5.6 - Webinar

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for Joshua Thijssen Joshua Thijssen
September 09, 2014
400

The new features of PHP 5.6 - Webinar

Avatar for Joshua Thijssen

Joshua Thijssen

September 09, 2014
Tweet

More Decks by Joshua Thijssen

Transcript

  1. PHP 5.6 - The new features 1 Webinar - 9

    sep 2014 dinsdag 9 september 14
  2. 2 Joshua Thijssen Netherlands Consultant and trainer @ TechAdemy Founder

    of TechAnalyze.io Author of PHP|Architect's "Mastering the SPL" Blog: http://adayinthelifeof.nl Email: [email protected] Twitter: @jaytaph dinsdag 9 september 14
  3. 4 Tech nalyze Assess technical skills automatically: PHP, Symfony2, Scrum

    - HTML5/CSS3 Javascript / JQuery dinsdag 9 september 14
  4. PHP 5.6 ➡ PHP 5.3 EOL 14 august 2014 5

    http://en.wikipedia.org/wiki/PHP#cite_note-releaseprocess-50 dinsdag 9 september 14
  5. PHP 5.6 ➡ PHP 5.3 EOL 14 august 2014 ➡

    PHP 5.5 EOL 20 june 2016 5 http://en.wikipedia.org/wiki/PHP#cite_note-releaseprocess-50 dinsdag 9 september 14
  6. PHP 5.6 ➡ PHP 5.3 EOL 14 august 2014 ➡

    PHP 5.5 EOL 20 june 2016 ➡ PHP 5.6 EOL 28 august 2017 5 http://en.wikipedia.org/wiki/PHP#cite_note-releaseprocess-50 dinsdag 9 september 14
  7. How to get it? ➡ http://blog.famillecollet.com/pages/ Config-en ➡ https://launchpad.net/~ondrej/ +archive/ubuntu/php5-5.6

    ➡ http://windows.php.net/download/ ➡ http://php-osx.liip.ch/ 6 dinsdag 9 september 14
  8. BC breaks? ➡ minor ➡ SSL Peer verification ➡ some

    array niches 7 dinsdag 9 september 14
  9. 1 <?php 2 3 class C 4 { 5 const

    ONE = 1; 6 7 public $a = array( 8 self::ONE => 'foo', 9 'bar', 10 'baz', 11 ); 12 } 13 14 $c = new C(); 15 var_dump($c->a); 8 PHP 5.5 - 5.6 compatibility break dinsdag 9 september 14
  10. 1 <?php 2 3 class C 4 { 5 const

    ONE = 1; 6 7 public $a = array( 8 self::ONE => 'foo', 9 'bar', 10 'baz', 11 ); 12 } 13 14 $c = new C(); 15 var_dump($c->a); 8 1 array(2) { 2 [0] => 3 string(3) "bar" 4 [1] => 5 string(3) "baz" 6 } php 5.5 PHP 5.5 - 5.6 compatibility break dinsdag 9 september 14
  11. 1 <?php 2 3 class C 4 { 5 const

    ONE = 1; 6 7 public $a = array( 8 self::ONE => 'foo', 9 'bar', 10 'baz', 11 ); 12 } 13 14 $c = new C(); 15 var_dump($c->a); 8 1 array(2) { 2 [0] => 3 string(3) "bar" 4 [1] => 5 string(3) "baz" 6 } php 5.5 1 array(3) { 2 [1]=> 3 string(3) "foo" 4 [2]=> 5 string(3) "bar" 6 [3]=> 7 string(3) "baz" 8 } php 5.6 PHP 5.5 - 5.6 compatibility break dinsdag 9 september 14
  12. Upgrading to php5.6 ➡ From 5.5: just read the migration

    guide ➡ http://php.net/manual/en/ migration56.php ➡ From 5.3: read the 5.4, 5.5 and 5.6 migration guides. 9 dinsdag 9 september 14
  13. 10 What's new in PHP 5.6? ➡ Constant scalar expressions

    ➡ Variadic functions ➡ Argument unpacking ➡ Exponentation ➡ Use function / Use const ➡ GMP operator overloading ➡ __debuginfo() ➡ SSL peer verification dinsdag 9 september 14
  14. 12 ➡ Use simple expressions to define constants. ➡ Evaluated

    during compile time, not runtime. dinsdag 9 september 14
  15. 1 <?php 2 3 class C 4 { 5 const

    BASE_LEVEL = 100; 6 7 const CONST_ONE = self::BASE_LEVEL + 1; 8 const CONST_TWO = self::BASE_LEVEL + 2; 9 const CONST_THREE = self::BASE_LEVEL + 3; 10 const CONST_FOUR = self::BASE_LEVEL + 4; 11 } 12 13 Constant expressions dinsdag 9 september 14
  16. 1 <?php 2 3 class C 4 { 5 const

    VALID = 1; 6 const CHECKED = 2; 7 const IN_SYNC = 512; 8 const PRIORITY = 4096; 9 } 10 14 Cleaner bitwise constants dinsdag 9 september 14
  17. 1 <?php 2 3 class C 4 { 5 const

    VALID = 1; 6 const CHECKED = 2; 7 const IN_SYNC = 512; 8 const PRIORITY = 4096; 9 } 10 14 1 <?php 2 3 class C 4 { 5 const VALID = 1 << 0; 6 const CHECKED = 1 << 1; 7 const IN_SYNC = 1 << 9; 8 const PRIORITY = 1 << 12; 9 } Cleaner bitwise constants dinsdag 9 september 14
  18. 16 ➡ But you can use: ➡ __FILE__, __CLASS__, __NAMESPACE__

    etc ➡ Constants from other classes dinsdag 9 september 14
  19. 16 ➡ But you can use: ➡ __FILE__, __CLASS__, __NAMESPACE__

    etc ➡ Constants from other classes ➡ String literals dinsdag 9 september 14
  20. 16 ➡ But you can use: ➡ __FILE__, __CLASS__, __NAMESPACE__

    etc ➡ Constants from other classes ➡ String literals ➡ Even the ternary operator dinsdag 9 september 14
  21. 17 1 <?php 2 3 class C 4 { 5

    const ONE = 1; 6 7 const LINE_ONE = "This is a line " . self::ONE; 8 } Different constant scalar expression examples dinsdag 9 september 14
  22. 17 1 <?php 2 3 class C 4 { 5

    const ONE = 1; 6 7 const LINE_ONE = "This is a line " . self::ONE; 8 } 1 ?php 2 3 class D 4 { 5 const ONE = 1; 6 } 7 class C 8 { 9 const THREE = D::ONE + 2; 10 } Different constant scalar expression examples dinsdag 9 september 14
  23. 1 class C 2 { 3 const LOG_LEVEL_HIGH = 105;

    4 5 const LOG_LEVEL_CRITICAL = self::LOG_LEVEL_HIGH >= 100 ? 250 : 100; 6 } 17 1 <?php 2 3 class C 4 { 5 const ONE = 1; 6 7 const LINE_ONE = "This is a line " . self::ONE; 8 } 1 ?php 2 3 class D 4 { 5 const ONE = 1; 6 } 7 class C 8 { 9 const THREE = D::ONE + 2; 10 } Different constant scalar expression examples dinsdag 9 september 14
  24. 19 ➡ It's nothing more than func_get_args() ➡ Uses '...'

    before the $argument dinsdag 9 september 14
  25. 19 ➡ It's nothing more than func_get_args() ➡ Uses '...'

    before the $argument ➡ More readable dinsdag 9 september 14
  26. 19 ➡ It's nothing more than func_get_args() ➡ Uses '...'

    before the $argument ➡ More readable ➡ Makes a bit more sense dinsdag 9 september 14
  27. 1 <?php 2 3 function foo(... $arguments) { 4 print_r($arguments);

    5 } 6 7 foo(1,2,3,4); 8 20 Using variadic arguments dinsdag 9 september 14
  28. 1 <?php 2 3 function foo(... $arguments) { 4 print_r($arguments);

    5 } 6 7 foo(1,2,3,4); 8 20 1 Array 2 ( 3 [0] => 1 4 [1] => 2 5 [2] => 3 6 [3] => 4 7 ) Using variadic arguments dinsdag 9 september 14
  29. 1 function findEarliestDate(\DateTime ... $arguments) { 2 $earliest = null;

    3 foreach ($arguments as $dt) { 4 if (! $earliest || $dt < $earliest) { 5 $earliest = $dt; 6 } 7 } 8 9 return $earliest; 10 } 11 12 $d1 = new DateTime('2014-01-31 10:42:29'); 13 $d2 = new DateTime('2014-01-01 00:00:00'); 14 $d3 = new DateTime('2020-04-01 12:13:41'); 15 $d4 = new DateTime('2010-04-01 12:13:41'); 16 $earliest = findEarliestDate(new DateTime(), $d1, $d2, $d3, $d4); 21 Using typehints dinsdag 9 september 14
  30. 1 <?php 2 3 function foo($level, $format = "html", ...

    $arguments) { 4 print "LEVEL: ".$level."\n"; 5 print "FORMAT: ".$format."\n"; 6 print_r($arguments); 7 } 8 9 foo(1, "text", 3, 4); 10 foo(1, "text"); 11 foo(1); 22 Mixing mandatory, optional and variadic arguments Variadic arguments must come last! dinsdag 9 september 14
  31. 1 <?php 2 3 function foo(... $args) { 4 print_r($args);

    5 } 6 7 $a = [ 1, "foo" => 2, 3, 4 ]; 8 foo(... $a); 23 Cannot use as associative arrays, only numerical arrays dinsdag 9 september 14
  32. 1 <?php 2 3 function foo(... $args) { 4 print_r($args);

    5 } 6 7 $a = [ 1, "foo" => 2, 3, 4 ]; 8 foo(... $a); 23 Catchable fatal error: Cannot unpack array with string keys Cannot use as associative arrays, only numerical arrays dinsdag 9 september 14
  33. 1 <?php 2 3 function foo(... $args) { 4 print_r($args);

    5 } 6 7 $a = [ 1, "foo" => 2, 3, 4 ]; 8 foo(... $a); 23 Catchable fatal error: Cannot unpack array with string keys Cannot use as associative arrays, only numerical arrays 1 foo(... array_values($a)); dinsdag 9 september 14
  34. 1 <?php 2 3 function foo(... $args) { 4 print_r($args);

    5 } 6 7 $a = [ 1, "foo" => 2, 3, 4 ]; 8 foo(... $a); 23 Catchable fatal error: Cannot unpack array with string keys Cannot use as associative arrays, only numerical arrays 1 foo(... array_values($a)); Might break a future named arguments feature dinsdag 9 september 14
  35. 24 ➡ Does it make sense? ➡ Automatic type hinting

    (but only one type) dinsdag 9 september 14
  36. 24 ➡ Does it make sense? ➡ Automatic type hinting

    (but only one type) ➡ Not so much for dynamic data (arrays), but more so for static dinsdag 9 september 14
  37. 26 ➡ Related to variadic functions ➡ "unpacks" array or

    anything that implements traversable into variables, just like list() does. ➡ splat operator ➡ Only usable in function calls dinsdag 9 september 14
  38. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 foo(1,2,3); 27 Simple function call with 3 arguments dinsdag 9 september 14
  39. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 foo(1,2,3); 27 Simple function call with 3 arguments 1 2 3 dinsdag 9 september 14
  40. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2, 3 ]; 10 11 list($tmp1, $tmp2, $tmp3) = $a; 12 foo($tmp1, $tmp2, $tmp3); 28 Using list() to extract elements first dinsdag 9 september 14
  41. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2, 3 ]; 10 11 list($tmp1, $tmp2, $tmp3) = $a; 12 foo($tmp1, $tmp2, $tmp3); 28 Using list() to extract elements first 1 2 3 dinsdag 9 september 14
  42. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2, 3 ]; 10 foo(... $a); 29 PHP 5.6 Argument unpacking dinsdag 9 september 14
  43. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2, 3 ]; 10 foo(... $a); 29 PHP 5.6 Argument unpacking 1 2 3 dinsdag 9 september 14
  44. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2, 3, 4, 5 ]; 10 foo(... $a); 30 PHP 5.6 Argument unpacking with overflow dinsdag 9 september 14
  45. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2, 3, 4, 5 ]; 10 foo(... $a); 30 PHP 5.6 Argument unpacking with overflow Fills up what needs to be filled, discards the rest dinsdag 9 september 14
  46. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2, 3, 4, 5 ]; 10 foo(... $a); 30 PHP 5.6 Argument unpacking with overflow Fills up what needs to be filled, discards the rest 1 2 3 dinsdag 9 september 14
  47. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2 ]; 10 foo(... $a); 31 PHP 5.6 Argument unpacking with underflow dinsdag 9 september 14
  48. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2 ]; 10 foo(... $a); 31 PHP 5.6 Argument unpacking with underflow Warning, but fills with NULL dinsdag 9 september 14
  49. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2 ]; 10 foo(... $a); 31 PHP 5.6 Argument unpacking with underflow Warning, but fills with NULL 1 2 NULL dinsdag 9 september 14
  50. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2 ]; 10 $b = new ArrayIterator([3, 4]); 11 foo(... $a, ... $b); 32 PHP 5.6 Multiple argument unpacks dinsdag 9 september 14
  51. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2 ]; 10 $b = new ArrayIterator([3, 4]); 11 foo(... $a, ... $b); 32 PHP 5.6 Multiple argument unpacks 1 2 3 dinsdag 9 september 14
  52. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2, 3 ]; 10 foo('foo', 'bar', ... $a); 33 Mixing argument unpacking with normal arguments dinsdag 9 september 14
  53. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2, 3 ]; 10 foo('foo', 'bar', ... $a); 33 Mixing argument unpacking with normal arguments foo bar 1 dinsdag 9 september 14
  54. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2 ]; 10 foo(... $a, 'foo', 'bar'); 34 Mixing argument unpacking with normal arguments dinsdag 9 september 14
  55. 1 <?php 2 3 function foo($a, $b, $c) { 4

    print_r($a); 5 print_r($b); 6 print_r($c); 7 } 8 9 $a = [ 1, 2 ]; 10 foo(... $a, 'foo', 'bar'); 34 Mixing argument unpacking with normal arguments Fatal error: Cannot use positional argument after argument unpacking dinsdag 9 september 14
  56. 36 ➡ ** operator (and **= as shorthand) ➡ power

    operator dinsdag 9 september 14
  57. 1 <?php 2 3 $a = 2 ** 3; 4

    print $a; 37 Power operator 8 dinsdag 9 september 14
  58. 1 <?php 2 3 $a = -2 ** 3; 4

    print $a . "\n"; 5 6 $a = -3 ** 2; 7 print $a . "\n"; 39 Associativity -8 // correct -9 // incorrect dinsdag 9 september 14
  59. 1 <?php 2 3 $a = (- 2) ** 3;

    4 print $a . "\n"; 5 6 $a = (- 3) ** 2; 7 print $a . "\n"; 40 Associativity -8 // correct 9 // correct dinsdag 9 september 14
  60. 42 ➡ Import/alias constants and functions into the current namespace.

    ➡ PHP 5.3: classes, interfaces, namespaces dinsdag 9 september 14
  61. 42 ➡ Import/alias constants and functions into the current namespace.

    ➡ PHP 5.3: classes, interfaces, namespaces ➡ PHP 5.6: constants, functions dinsdag 9 september 14
  62. 44 1 <?php 2 3 namespace Foo; 4 5 function

    bar($namespace) { 6 print "This is " . __FUNCTION__ . ", and called from namespace ". $namespace. "\n"; 7 } 8 9 namespace Another\Name; 10 11 use function Foo\bar; 12 13 bar(__NAMESPACE__); // Calls the Foo\bar() method Use function dinsdag 9 september 14
  63. 44 1 <?php 2 3 namespace Foo; 4 5 function

    bar($namespace) { 6 print "This is " . __FUNCTION__ . ", and called from namespace ". $namespace. "\n"; 7 } 8 9 namespace Another\Name; 10 11 use function Foo\bar; 12 13 bar(__NAMESPACE__); // Calls the Foo\bar() method Use function This is Foo\bar, and called from namespace Another\Name dinsdag 9 september 14
  64. 45 1 <?php 2 3 namespace Foo; 4 5 function

    bar($namespace) { 6 print "This is " . __FUNCTION__ . ", and called from namespace ". $namespace. "\n"; 7 } 8 9 namespace Another\Name; 10 11 use function Foo\bar as foobar; 12 13 foobar(__NAMESPACE__); // Calls the Foo\bar() method Use function with aliasing dinsdag 9 september 14
  65. 45 1 <?php 2 3 namespace Foo; 4 5 function

    bar($namespace) { 6 print "This is " . __FUNCTION__ . ", and called from namespace ". $namespace. "\n"; 7 } 8 9 namespace Another\Name; 10 11 use function Foo\bar as foobar; 12 13 foobar(__NAMESPACE__); // Calls the Foo\bar() method Use function with aliasing This is Foo\bar, and called from namespace Another\Name dinsdag 9 september 14
  66. 46 ➡ You can still define the same functions and

    use them in your own namespace ➡ Could break things easily dinsdag 9 september 14
  67. 47 1 <?php 2 3 namespace Foo; 4 5 function

    bar($namespace) { 6 print "This is " . __FUNCTION__ . ", and called from namespace ". $namespace. "\n"; 7 } 8 9 namespace Another\Name; 10 11 use function Foo\bar; 12 13 // Can be defined without any problems 14 function bar() { 15 print "Bar!"; 16 } 17 18 bar(__NAMESPACE__); // Calls the Foo\bar() method 19 20 \Another\Name\bar(); // Calls our own bar() method Multiple function defines dinsdag 9 september 14
  68. 47 1 <?php 2 3 namespace Foo; 4 5 function

    bar($namespace) { 6 print "This is " . __FUNCTION__ . ", and called from namespace ". $namespace. "\n"; 7 } 8 9 namespace Another\Name; 10 11 use function Foo\bar; 12 13 // Can be defined without any problems 14 function bar() { 15 print "Bar!"; 16 } 17 18 bar(__NAMESPACE__); // Calls the Foo\bar() method 19 20 \Another\Name\bar(); // Calls our own bar() method Multiple function defines This is Foo\bar, and called from namespace Another\Name Bar! dinsdag 9 september 14
  69. ➡ Just like regular functions, it automatically falls back to

    the global namespace when the function is not found. ➡ RFC says otherwise 48 dinsdag 9 september 14
  70. 49 1 <?php 2 3 // Foo namespace 4 namespace

    Foo { 5 6 function strlen($str) 7 { 8 return "The length of the string is: " . \strlen($str) . "\n"; 9 } 10 11 } 12 13 14 // Another\Name namespace 15 namespace Another\Name { 16 17 use function Foo\strlen; 18 19 print strlen(__NAMESPACE__); // Calls \Foo\strlen() function 20 21 } Fallbacks dinsdag 9 september 14
  71. 50 1 <?php 2 3 // Foo namespace 4 namespace

    Foo { 5 6 function strlen($str) 7 { 8 return "The length of the string is: " . \strlen($str) . "\n"; 9 } 10 11 } 12 13 14 // Another\Name namespace 15 namespace Another\Name { 16 17 print strlen(__NAMESPACE__); // Falls back to the global strlen() function 18 19 } Fallbacks dinsdag 9 september 14
  72. 51 1 <?php 2 3 // Global namespace 4 namespace

    { 5 6 function strlength($str) 7 { 8 return "Hi there. This is the global strlength() function: " . strlen($str) . "\n"; 9 } 10 11 } 12 13 // Foo namespace 14 namespace Foo { 15 16 function strlength($str) 17 { 18 return "The length of the string is: " . \strlen($str) . "\n"; 19 } 20 21 } 22 23 24 // Another\Name namespace 25 namespace Another\Name { 26 27 print strlength(__NAMESPACE__); // Falls back to the the \strlength() method 28 29 } Automatic fallback to global namespace dinsdag 9 september 14
  73. 53 ➡ New concept in PHP: Operator overloading ➡ Only

    GMP extension ➡ More to follow, most likely dinsdag 9 september 14
  74. 1 <?php 2 3 $a = 1 + 2; 4

    var_dump($a); // int(3) 5 6 $a = 1 + 1.1; 7 var_dump($a); // float(2.1) 8 9 $a = "foo" + 1; 10 var_dump($a); // int(1) 11 12 $a = 1 + "foo"; 13 var_dump($a); // int(1) 14 15 $a = new Color("yellow") + new Color("blue"); 16 var_dump($a); // Color("green") ??? 54 PHP "acts" differently based on operands given dinsdag 9 september 14
  75. 1 <?php 2 3 $a = gmp_init(1) + gmp_init(5); 4

    var_dump($a); 55 object(GMP)#3 (1) { ["num"]=> string(1) "6" } GMP "overloads" the operators dinsdag 9 september 14
  76. 1 <?php 2 3 $a = gmp_init(1) + 2; 4

    var_dump($a); 56 object(GMP)#3 (1) { ["num"]=> string(1) "3" } GMP "overloads" the operators dinsdag 9 september 14
  77. 1 <?php 2 3 $a = gmp_init(1) + 2; 4

    var_dump($a); // GMP(3) 5 6 $a = 8 + gmp_init(1); 7 var_dump($a); // GMP(9) 8 9 $a = 8.6 + gmp_init(1); 10 var_dump($a); // Unable to convert variable to GMP 11 12 $a = true + gmp_init(1); 13 var_dump($a); // GMP(2) 14 15 $a = false + gmp_init(1); 16 var_dump($a); // GMP(1) 57 GMP can convert only INT and BOOL, not FLOAT :( dinsdag 9 september 14
  78. 58 ➡ GMP operator overloading is not meant to start

    userland overloading (opr_add, coerce etc) ➡ It's just to make GMP usage easier dinsdag 9 september 14
  79. 1 $result = gmp_mod( 2 gmp_add( 3 gmp_mul($c0, gmp_mul($ms0, gmp_invert($ms0,

    $n0))), 4 gmp_add( 5 gmp_mul($c1, gmp_mul($ms1, gmp_invert($ms1, $n1))), 6 gmp_mul($c2, gmp_mul($ms2, gmp_invert($ms2, $n2))) 7 ) 8 ), 9 gmp_mul($n0, gmp_mul($n1, $n2)) 10 ); 11 12 $result = ( 13 $c0 * $ms0 * gmp_invert($ms0, $n0) 14 + $c1 * $ms1 * gmp_invert($ms1, $n1) 15 + $c2 * $ms2 * gmp_invert($ms2, $n2) 16 ) % ($n0 * $n1 * $n2); 59 Clearer way to deal with GMP numbers https://wiki.php.net/rfc/operator_overloading_gmp dinsdag 9 september 14
  80. 61 ➡ New magic method ➡ Allows to control the

    output of var_dump() dinsdag 9 september 14
  81. 1 <?php 2 3 class Foo { 4 protected $file;

    5 6 function __construct($path = null) { 7 if ($path != null) { 8 $this->file = fopen($path, "r"); 9 } 10 } 11 12 } 13 14 $foo = new Foo("/etc/passwd"); 15 print_r($foo); 62 Simple class with file resource Foo Object ( [file:protected] => Resource id #5 ) dinsdag 9 september 14
  82. 1 class Foo { 2 protected $file; 3 4 function

    __construct($path = null) { 5 if ($path != null) { 6 $this->file = fopen($path, "r"); 7 } 8 } 9 10 function __debuginfo() { 11 $debuginfo = array(); 12 13 $debuginfo['opened'] = $this->file ? "true" : "false"; 14 15 if ($this->file) { 16 $debuginfo['file'] = stream_get_meta_data($this->file); 17 } 18 return $debuginfo; 19 } 20 21 } 22 23 $foo = new Foo("/etc/passwd"); 24 print_r($foo); 25 26 $bar = new Foo(); 27 print_r($bar); 63 Simple class with file resource and __debuginfo dinsdag 9 september 14
  83. 1 class Foo { 2 protected $file; 3 4 function

    __construct($path = null) { 5 if ($path != null) { 6 $this->file = fopen($path, "r"); 7 } 8 } 9 10 function __debuginfo() { 11 $debuginfo = array(); 12 13 $debuginfo['opened'] = $this->file ? "true" : "false"; 14 15 if ($this->file) { 16 $debuginfo['file'] = stream_get_meta_data($this->file); 17 } 18 return $debuginfo; 19 } 20 21 } 22 23 $foo = new Foo("/etc/passwd"); 24 print_r($foo); 25 26 $bar = new Foo(); 27 print_r($bar); 63 Simple class with file resource and __debuginfo Foo Object ( [opened] => true [file] => Array ( [wrapper_type] => plainfile [stream_type] => STDIO [mode] => r [unread_bytes] => 0 [seekable] => 1 [uri] => /etc/passwd [timed_out] => [blocked] => 1 [eof] => ) ) Foo Object ( [opened] => false ) dinsdag 9 september 14
  84. 65 ➡ https://wiki.php.net/rfc/operator_overloading_gmp ➡ http://php.net/manual/en/migration56.php ➡ http://php.net/manual/en/migration56.new-features.php ➡ https://wiki.php.net/rfc/const_scalar_exprs ➡

    https://wiki.php.net/rfc/variadics Further reading materials: ➡ http://phpdancer.blogspot.nl/p/php-wallpapers.html dinsdag 9 september 14
  85. 66 Find me on twitter: @jaytaph Find me for development

    and training: www.noxlogic.nl Find me on email: [email protected] Find me for blogs: www.adayinthelifeof.nl Thanks for your attention https://joind.in/event/view/2584 Please leave feedback at dinsdag 9 september 14