PHP Digest # 195 (14 al 28 de diciembre de 2020)



Nueva selección con enlaces a noticias y materiales. En este número: Fibras para PHP asincrónico, primeros atributos nativos, short match y otras propuestas RFC para PHP 8.1, herramientas, muchos videos, artículos y podcasts.



¡Feliz lectura y próspero año nuevo!









Internos de PHP



  • [RFC] Fibras - Una gran propuesta para PHP asincrónico. Más detalles estaban en el canal de Telegram . En definitiva, se trata de una versión mejorada de generadores, que te permitirá escribir código asincrónico basado en bibliotecas como ReactPHP / Amp mucho más fácil y comprensible.





    Amp v3 aún está en desarrollo, pero ya usa fibras en lugar de promesas. Aquí hay un ejemplo de cómo se ve el análogo async / await:
    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 matchmatch



    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

















Entretenido














Hoy habrá el segundo flujo de PHP Digest. Todas las novedades y enlaces del número + más detalles, un resumen de lo enviado, interesante pero no incluido en el número, los resultados del dibujo y un nuevo concurso con elefantes.

A partir de las 20:00 Moscú, Minsk / 19:00 Kiev.



Encuesta: Resumiendo PHP Year y Playing the Elephant






Si observa un error o inexactitud, háganoslo saber en un habr o telegrama personal .





Más noticias y comentarios en el canal PHP Digest Telegram .



Enviar enlace

Buscar enlaces en todos los resúmenes

Número anterior: PHP Digest # 194




All Articles