PHP Annotated Monthly – May 2019

PHP Annotated Monthly

Greetings everyone,

Please welcome the May edition of PHP Annotated Monthly. Inside we have all the latest news and material from the world of PHP. Read all about the PHP updates, Codeception, WordPress, and other releases. PHP 7.4 is shaping up with a few new RFC proposals accepted including arrow functions, Zend Framework becomes Laminas, news from Laravel, Yii, and Symfony, some async PHP stuff, useful tools, and a whole lot more!

⚡️ News & Releases

🐘 PHP Internals

  • [RFC] Arrow Functions 2.0 — The proposal has passed the vote and is now accepted! We’ll get short closures in PHP 7.4. The original syntax fn() => is used and it also has automatic scope binding by value:
    $y = 1;
    $fn = fn($x) => $x + $y;

    So far arrow functions can only have a single statement. Multiline functions are part of the future scope and may be implemented later. The hack with the && operator, like you can do in JavaScript, will not work:

    andOperator = ($x) => ($y = 40) && $x + $y;
    console.log(andOperator(2)); // 42
    $andOperator = fn($x) => ($y = 40) && $x + $y;
    var_dump($andOperator(2)); // bool(true)

    But it is possible to do a workaround with array functions:

    $multipleLines = fn($x) => array_slice([
    $y = $x * 8,
    $z = $y + 8,
    $x + $y + $z
    ], -1)[0];
    var_dump($multipleLines(2)); // int(42)
  • [RFC] Deprecate PHP Short open tags — The proposal considered eliminating the tags <?, but it faced a wave of resentment and arguments. And although it was accepted, it looks like the deprecation will be postponed.
  • [RFC] Spread Operator in Array Expression — Almost unanimous voting makes it possible to use the ... operator in arrays.
    $parts = ['apple', 'pear'];
    $fruits = ['banana', 'orange', ...$parts, 'watermelon'];
    // ['banana', 'orange', 'apple', 'pear', 'watermelon'];

    Also it can help convert an iterator to an array instead of using iterator_to_array:

    $array = [...$iter];
  • [RFC] Allow throwing exceptions from __toString() — Nikita continues fixing “PHP Sadnesses” one by one. He is working on an old issue of throwing exceptions in a __toString(). Another useful and not trivial improvement for PHP 7.4, which will save us from using workarounds like 1, 2.
  • [RFC] Deprecate left-associative ternary operator — Almost all programming languages have the ternary operator calculated from right to left, but this is different in PHP it was a potential source of bugs. The proposal to deprecate left associativity is now accepted, and if a nested ternary is needed then the precedence should be explicitly declared with brackets.
    1 ? 2 : 3 ? 4 : 5;   // deprecated
    (1 ? 2 : 3) ? 4 : 5; // ok
    1 ? 2 : (3 ? 4 : 5); // ok
  • With all the accepted RFC’s PHP 7.4 is going to be amazing! Read a nice recap on what’s New in PHP 7.4.
  • Derick Rethans has recorded a whole load of new episodes of PHP Internals News:
    • 🔈 #6 — On PHP and extensions quality with Remi Collet.
    • 🔈 #7 — On JIT in PHP 8 and earlier attempts with Zeev Suraski.
    • 🔈 #8 — On Short tags with George Banyard.
    • 🔈 #9 — On bundled extensions with Kalle Nielsen.

🛠 Tools




🌀 Async PHP

💡 Misc

🎥 Audio & Video

Thanks for reading!

If you have any interesting links to share via PHP Annotated Monthly, please leave a comment or drop me a message on Twitter.

Subscribe to PHP Annotated

Your JetBrains PhpStorm Team
The Drive to Develop

image description