PHP Digest 155 (April 22 - May 6, 2019)

PHP Digest 155 (April 22 - May 6, 2019)



Fresh collection with links to news and materials. In the release: updates to PHP, Codeception 3.0 and other releases, short lambdas in PHP 7.4 and an overview of the latest RFC proposals from PHP Internals, a portion of useful tools, and much more.

Happy reading!



News and Releases



PHP Internals


  • [RFC] Arrow Functions 2.0 - The proposal has passed the vote and accepted. Now PHP will have short anonymous functions using the syntax fn () = & gt; and automatically grabbing variables from an external scop by value:
      $ y = 1;
     $ fn = fn ($ x) = & gt;  $ x + $ y;
      

    As long as functions can have only one expression strictly, the result of which will be returned. Multi-line functions may be implemented later. Hack using the & amp; & amp; as in JS does not work:
    Hidden text
      andOperator = (  $ x) = & gt;  ($ y = 10) & amp; & amp;  $ x + $ y;
     console.log (andOperator (5));//15
      
      $ andOperator = fn ($ x) = & gt;  ($ y = 10) & amp; & amp;  $ x + $ y;
     var_dump ($ andOperator (5));//bool (true)
      
    But you can use a hack using end () :
    Hidden text
      & lt;? php
    
     function last (... $ args) {
      return end ($ args);
     }
    
     $ multipleLines = fn ($ x) = & gt;  last (
      $ y = $ x * 10,//10
      $ z = $ y + 15,//25
      $ x + $ y + $ z//1 + 10 + 25 The result of this expression is returned from last ()
     );
     var_dump ($ multipleLines (1));//int (36)
    
      
  • [RFC] Deprecate PHP Short open tags - The proposal considered the idea of ​​removing the possibility of using short tags & lt; ? , but it was greeted by a storm of disturbances and disputes. Therefore, a much softer way was proposed , in which in the next versions the possibility remains available as is and deprecation warning will be thrown .
  • [RFC] Spread Operator in Array Expression - Offer accepted almost unanimously. The ... operator will now be available in arrays.
    Hidden text
      $ parts = ['apple', '  pear '];
     $ fruits = ['banana', 'orange', ... $ parts, 'watermelon'];//['banana', 'orange', 'apple', 'pear', 'watermelon'];
      
    You can also use it to quickly convert an iterator into an array instead of using iterator_to_array :
      $ array  = [... $ iter];
      
  • RFC: Allow throwing exceptions from __toString () - Nikita continues to systematically correct prusty PHP " one by one. This time we are talking about the possibility of throwing an exception in __ toString () . Another nice and not at all trivial improvement for PHP 7.4, which eliminates the need to use any workarounds 1 , 2 .
  • audio PHP Internals News # 7 - Derick Rethans talks with Zeev Suraski about JIT in PHP 8 and earlier implementation attempts.
  • audio PHP Internals News # 8 - Chatting with George Banyard, PHP documentation contributor, about short tags.

Tools



Symfony



Laravel



Yii



Async PHP



Training Materials



Thank you for your attention!

If you notice an error or inaccuracy - please report it to PM .
For questions and suggestions, write to mail or twitter .

More news and comments on the PHP Digest Telegram Channel .

send link
Search links for all digests
  ← Previous release: PHP Digest No. 154

Source text: PHP Digest 155 (April 22 - May 6, 2019)