PHP Digest # 195 (December 14 - 28, 2020)



Fresh selection with links to news and materials. In this issue: Fibers for asynchronous PHP, first native attributes, short match and other RFC proposals for PHP 8.1, tools, many videos, articles and podcasts.



Happy reading and Happy New Year!









PHP Internals



  • [RFC] Fibers - A great proposal for asynchronous PHP. More details were in the Telegram channel . In short, this is an improved version of generators, which will allow you to write asynchronous code based on libraries like ReactPHP / Amp much easier and more understandable.





    Amp v3 is still in development, but already uses fibers instead of promises. Here's an example of what the async / await analog looks like:
    use Amp\Delayed;
    use Amp\Loop;
    use function Amp\async;
    use function Amp\await;
    
    //  ,    int  ,     ,      .
    $callback = function (int $id): int {
        return await(new Delayed(1000, $id)); // Await promise resolution.
    };
    
    //  $callback  int, but is executed asynchronously.
    $result = $callback(1); //      ,  1 .
    \var_dump($result);
    
    //      ,        .
    $result = await([  //  ,    1 .
        async($callback, 2),
        async($callback, 3),
    ]);
    \var_dump($result); //   2     .
          
          



  • [RFC] #[Deprecated] Attribute โ€” PHP 8 , . โ€” #[Deprecated]



    . , #[Deprecated]



    , PHP E_DEPRECATED



    .



    , , .



    , PhpStorm 2020.3. , . , - final, .
  • [RFC] #[NamedParameterAlias] Attribute โ€” PHP 8.1.



    , โ€” . , API .



    RFC: Named Parameters explicit opt in.



    โ€” , , .
    <?php
    
    use NamedParameterAlias;
    
    // Old function signature:
    function log($arg1) {}
    
    // New function signature introduces better name
    function log(#[NamedParameterAlias("arg1")] $message) {}
    
    log(arg1: "Hello World!");
    log(message: "Hello World!");
    
          
          



    Attribute::IS_REPEATABLE



    . , .
  • [RFC] Short match โ€” match



    PHP 8 switch



    .



    switch(true) { ...



    , if-elseif-...else



    . match(true)



    .



    RFC match



    match(true)



    .

    PHP 8.0:
    $a = 3;
    
    print match (true) {
      $a < 2 => 'small',
      $a == 3 => 'medium',
      default => 'large',
    };
    
          
          



    :
    $a = 3;
    
    print match {
      $a < 2 => 'small',
      $a == 3 => 'medium',
      default => 'large',
    };
    
          
          



    ยซยป.
  • [RFC] Configurable callback to dump results of expressions in `php -a` โ€” Tyson Andre php -a



    .



    bobthecow/psysh, PHP . .
  • [RFC] Add is_list(mixed $value): bool โ€” RFC Tyson Andre. is_list()



    , true



    , 0, 1, 2 ... count($value)-1



    .

  • [PR] Add support for property initialization during cloning โ€” - .
    class Foo
    {
        public $bar;
        public $baz;
    
        public function withProperties($bar, $baz)
        {
            $self = clone $this;
            $self->bar = $bar;
            $self->baz = $baz;
    
            return $self;
        }
    }
    
    class Foo
    {
        public $bar;
        public $baz;
    
        public function withProperties($bar, $baz)
        {
            return clone $this with {
                bar: $bar,
                baz: $baz,
            };
        }
    }
    
          
          









Symfony





Laravel





Yii

















Entertaining














Today there will be the second PHP Digest stream. All news and links from the issue + more details, an overview of what was sent, interesting but not included in the issue, the results of the drawing and a new contest with elephants.

Beginning at 20:00 Moscow, Minsk / 19:00 Kiev.



Poll: Summing Up PHP Year and Playing the Elephant






If you notice an error or inaccuracy, please let us know in a personal habr or telegram .





More news and comments on the PHP Digest Telegram channel .



Send link

Search links in all digests

โ† Previous issue: PHP Digest # 194




All Articles