Home Development of Websites PHP Digest # 174 (February 10 – 24, 2020)

PHP Digest # 174 (February 10 – 24, 2020)

by admin

PHP Digest # 174 (February 10 - 24, 2020)

A fresh selection with links to news and materials.In the issue: 5 new RFCs from PHP Internals, as well as a language development proposal and a couple of prototypes of new features in the form of pool-requests, a portion of useful tools, videos, podcasts, and much more.
Enjoy reading!

PHP Digest # 174 (February 10 - 24, 2020) Newsreleases

PHP Digest # 174 (February 10 - 24, 2020) PHP Internals

  • Language evolution – Nikita’s suggestion on how to keep moving PHP forward without breaking legacy code.Read more at digest channel , and a discussion at pool-request
  • Accepted : [RFC] Variable Syntax Tweaks , [RFC] Static return type , [RFC] Allow ::class on objects
  • [RFC] Write-Once Properties – It is proposed to add a new modifier for properties which will allow to initialize properties but forbid to modify them.The question of the name of the modifier remains open, of the options : final , immutable , readonly , writeonce , locked , sealed Hidden text
    class Foo{<keyword> public int $a = 1;<keyword> public string $b;<keyword> public array $c = ["foo"];<keyword> public object $d;public function __construct(){$this-> b = "foo";}}$foo = new Foo();$foo-> a = 42; // EXCEPTION: property a has already been initialized$foo-> b = "bar"; // EXCEPTION: property b has already been initialized$foo-> a++; // EXCEPTION: incrementing/decrementing is forbiddenunset($foo-> c); // EXCEPTION: unsetting is forbidden$foo-> c[] = "bar"; // EXCEPTION: arrays can't be modified$var= $this-> c; // EXCEPTION: reference isn't allowed$foo-> d = new Foo(); // SUCCESS: property d hasn't been initialized before$foo-> d-> foo = "foo"; // SUCCESS: objects are still mutable internally

    This sentence has a good chance.It would probably be forbidden to set a default value for such properties, since it is essentially the same as a class constant.

  • [RFC] str_contains – It is suggested to add the function str_contains(string $haystack , string $needle) :bool , which checks if a string is contained in another string instead of using strpos() or strstr()
  • [RFC] Object-based token_get_all()alternative – It is suggested to add an alternative for the current function token_get_all() which, instead of a mix of strings and arrays, would return an array of objects PhpToken
  • [RFC] get_debug_type – Another helper function : the combination gettype() and get_class()
  • [RFC] Allow explicit call-site pass-by-reference annotation – Nikita’s updated RFC is up for discussion again. It is proposed to make it possible to explicitly specify pass-by-reference arguments. Thus alerting the developer that the passed variable will change. This time it is also proposed to add a directive to make the mode optional. Hidden text
    declare(require_explicit_send_by_ref=1);function byRef($ref) {...}byRef($var);
  • [Pre-RFC] Add support for "decorator" pattern – Nikita posted a prototype implementation of the "decorator" pattern for PHP. Hidden text
    interface Foo {public function method1(int $a):void;public function method2(): int;public function method3(string $b): string;public function method4(): stdClass;// ...}class ComposedFoo implements Foo {public Foo $inner;public function __construct(Foo $inner) { $this-> inner = $inner; }public function method4(): stdClass {return $DO_SOMETHING_DIFFERENT_HERE;}}/*The property is marked decorated, which means that automatically will be addedredirection methods for all public Foo methods, unless they are explicitlyoverridden in the class. These methods will have full signatures, so theystill satisfy the interface.*/
  • [PR] Use serialize_precision for printing floats in var_dump() – This change will affect the way the float numbers when output via var_dump() ( 0.1 + 0.2 === 0.30000000000000004 ): Hidden Text
    // Was$sum = 0.1 + 0.2;var_dump($sum); // float(0.3)var_dump($sum == 0.3); // bool(false) WTF???// Will become$sum = 0.1 + 0.2;var_dump($sum); // float(0.30000000000000004)var_dump($sum == 0.3); // bool(false) Makes sense...


PHP Digest # 174 (February 10 - 24, 2020) Symfony

PHP Digest # 174 (February 10 - 24, 2020) Laravel

PHP Digest # 174 (February 10 - 24, 2020) Yii

Async PHP

PHP Digest # 174 (February 10 - 24, 2020) Training materials

PHP Digest # 174 (February 10 - 24, 2020) Audio/Video

Thank you for your attention!
If you notice an error or inaccuracy, please tell us at email
Send questions and suggestions to email or at Twitter
More news and comments in our Telegram-channel PHP Digest
Send link – Let’s try via GitHub.
Search for links across all digests
Previous issue : PHP Digest #173

You may also like