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

What's new in PHP 7? - Coolblue Behind The Scenes 2016

What's new in PHP 7? - Coolblue Behind The Scenes 2016

PHP 7 talk I presented at Coolblue Behind The Scenes.

Go to https://talks.feryn.eu/talks/161/what-s-new-in-php-7-behind-the-scenes-rotterdam to see more details.

Thijs Feryn

July 19, 2016
Tweet

More Decks by Thijs Feryn

Other Decks in Technology

Transcript

  1. PHP 7.0: December 3rd 2015 PHP 5.6: 2014 PHP 5.5:

    2013 PHP 5.4: 2012 PHP 5.3: 2009 PHP 5.2: 2006 PHP 5.1: 2005 PHP 5.0: 2004
  2. ✓Namespaces ✓Late static binding ✓Goto labels ✓Object casting to primitives

    ✓Type hinting ✓APC ✓Non-fatal errors should become exceptions PHP 6 extra language features
  3. ✓UTF-16 or UTF-8? Or even UTF-32? ✓Few people know intricacies

    of Unicode & ICU ✓Major performance penalty (300%) ✓Too much effort to port all code PHP 6 unicode difficulties
  4. Ah, Jani went a little crazy today in his typical

    style to force a decision. The real decision is not whether to have a version 5.4 or not, it is all about solving the Unicode problem. The current effort has obviously stalled. We need to figure out how to get development back on track in a way that people can get on board. We knew the Unicode effort was hugely ambitious the way we approached it. There are other ways. So I think Lukas and others are right, let's move the PHP 6 trunk to a branch since we are still going to need a bunch of code from it and move development to trunk and start exploring lighter and more approachable ways to attack Unicode. We have a few already. Enhanced mbstring and ext/intl. Let's see some good ideas around that and work on those in trunk. Other features necessarily need to play along with these in the same branch. I refuse to go down the path of a 5.4 branch and a separate Unicode branch again. The main focus here needs to be to get everyone working in the same branch. -Rasmus March 11 2010
  5. When we aren't looking for pictures of kittens on the

    internet, internals developers are nearly always looking for ways to improve PHP, a few developers have a focus on performance. Over the last year, some research into the possibility of introducing JIT compilation capabilities to PHP has been conducted. During this research, the realization was made that in order to achieve optimal performance from PHP, some internal API's should be changed. This necessitated the birth of the phpng branch, initially authored by Dmitry Stogov, Xinchen Hui, and Nikita Popov. This branch does not include JIT capabilities, but rather seeks to solve those problems that prohibit the current, and any future implementation of a JIT capable executor achieving optimal performance by improving memory usage and cleaning up some core API's. By making these improvements, the phpng branch gives us a considerable performance gain in real world applications, for example a 20% increase in throughput for Wordpress. The door may well now be open for a JIT capable compiler that can perform as we expect, but it's necessary to say that these changes stand strong on their own, without requiring a JIT capable compiler in the future to validate them. The name "Next Generation" was optimistically presumptuous; in reality phpng is an internal project that we are working on, it is not a production ready branch that anyone should deploy, or judge as they would a release of PHP. The work on phpng, the doors it opens, the conversations it has started, the collaboration it is inspiring, are all worth getting excited about. But, we need to stay grounded, honest, and open; and say that there is much work to do in order to make the "Next Generation" a reality, this is only the start. May 27th 2014 by Joe Watkins
  6. Hi, Joe made a post about the introduction on phpng,

    what it is, and what it isn't. Some people (myself included) didn't liked that post for various reasons (some says it is opiniated, some doesn't like the tone and the wording, others feel that it is too early to made official announcement about phpng).. There were a couple of iteration on improving the text, but it is still not up to our standards imo: http://git.php.net/?p=web/php.git;a=history;f=archive/entries/2014-05-27-1.xml ; It is already on hackernews and reddit, so while some people suggested, I think it would be a bad move to just remove it. Would like to know what do you guys think about the best step, I see the following possible options: - keep it as is - remove it - rewrite it to be more formal and factual(only talk about what it is atm. not what it could be in the future). - create a post explaining that this post is controversional among the core-devs, so it is reflects more of the authors opinion than the projects official view on the topic. I'm mostly interested on the opinion of the core devs, but others also welcome to reply. -- Ferenc Kovács @Tyr43l - http://tyrael.hu May 28th 2014
  7. Balance between PHP as a easy-to-use scripting language and a

    mature future-proof programming language
  8. ✓Scalar type hints ✓Return type declarations ✓Anonymous classes ✓Closure::call() ✓Generator

    delegation ✓Generator return expressions ✓Null coalesce operator ✓Space ship operator ✓Throwables ✓Uniform variable syntax ✓… PHP 7 new language features
  9. <?php /** * Scalar type declarations */ //declare(strict_types=1); function add(int

    $a, int $b) { return $a + $b; } var_dump(add(1,2)); var_dump(add("1","2"));
  10. Fatal error: Uncaught TypeError: Argument 1 passed to add() must

    be of the type integer, string given TypeError: Argument 1 passed to add() must be of the type integer, string given
  11. <?php /** * Return type declarations */ //declare(strict_types=1); function add(int

    $a, int $b): int{ return (string)($a + $b); } var_dump(add(1,2));
  12. Fatal error: Uncaught TypeError: Return value of add() must be

    of the type integer, string returned TypeError: Return value of add() must be of the type integer, string returned
  13. <?php //Type error try { function add(int $a, int $b):int

    { return $a + $b; } echo add(array(), array()); } catch (TypeError $t) { echo "Type error: ".$t->getMessage().PHP_EOL; }
  14. <?php /** * Throwable interface */ //Error as Throwable try

    { sqdf(); } catch (Throwable $t) { echo "Throwable: ".$t->getMessage().PHP_EOL; } //Exception as Throwable try { throw new Exception("Bla"); } catch (Throwable $t) { echo "Throwable: ".$t->getMessage().PHP_EOL; }
  15. <?php /** * Throwable interface */ //Exception try { throw

    new Exception("Bla"); } catch (Error $e) { echo "Error: ".$e->getMessage().PHP_EOL; } catch (Exception $e) { echo "Exception: ".$e->getMessage().PHP_EOL; } //Type error try { function add(int $a, int $b):int { return $a + $b; } echo add(array(), array()); } catch (TypeError $t) { echo "Type error: ".$t->getMessage().PHP_EOL; }
  16. <?php /** * Anonymous classes */ $foo = new class

    { public function foo() { return "bar"; } }; var_dump($foo,$foo->foo());
  17. <?php function gen_one_to_three() { for ($i = 1; $i <=

    3; $i++) { yield $i; } } $generator = gen_one_to_three(); foreach ($generator as $value) { echo "$value\n"; }
  18. <?php /** * Generator delegation */ function gen() { yield

    1; yield 2; yield from gen2(); } function gen2() { yield 3; yield 4; } foreach (gen() as $val) { echo $val, PHP_EOL; }
  19. <?php /** * Generator return expressions */ $gen = (function()

    { yield 1; yield 2; return 3; })(); foreach ($gen as $val) { echo $val, PHP_EOL; } echo $gen->getReturn(), PHP_EOL;
  20. <?php /** * Space ship operator */ $array = [

    "1 <=> 1" => 1 <=> 1, "1 <=> 2" =>1 <=> 2, "2 <=> 1" => 2 <=> 1 ]; var_dump($array); array(3) { '1 <=> 1' => int(0) '1 <=> 2' => int(-1) '2 <=> 1' => int(1) } Output
  21. <?php /** * Null coalesce operator */ $array = ['foo'=>'bar'];

    //PHP5 style $message = isset($array['foo']) ? $array['foo'] : 'not set'; echo $message.PHP_EOL; //PHP7 style $message = $array['foo'] ?? 'not set'; echo $message.PHP_EOL;
  22. <?php /** * Closure::call() */ class Foo { private $foo

    = 'bar'; } $getFooCallback = function() { return $this->foo; }; //PHP5 style $binding = $getFooCallback->bindTo(new Foo,'Foo'); echo $binding().PHP_EOL; //PHP7 style echo $getFooCallback->call(new Foo).PHP_EOL;
  23. Typedef struct _zval_struct { union { long lval; double dval;

    struct { char *val; int len; } str; HashTable *ht; struct { zend_object_handle handle; zend_object_handlers *handlers; } obj; } value; zend_uint refcount; zend_uchar type; zend_uchar is_ref; } zval; Typedef struct _zval_struct { union { long lval; double dval; zend_refcounted *counted; zend_string *str; zend_array *arr; zend_object *obj; zend_resource *res; zend_reference *ref; void *ptr; } value; union { struct { zend_uchar type; zend_uchar flags; }; zend_uint type_info; }; zend_uint reserved; } zval; PHP 5 vs PHP 7