PHP Digest No. 174 (10 - 24 Februari 2020)


Seleksi segar dengan tautan ke berita dan bahan. Dalam masalah ini: 5 RFC baru dari PHP Internal, serta proposal untuk mengembangkan bahasa dan beberapa prototipe fitur baru dalam bentuk permintaan kumpulan, sebagian dari alat yang berguna, video, podcast, dan banyak lagi.

Selamat membaca!



Berita dan Siaran



PHP Internals


  • Language evolution β€” , PHP , . , -.
  • : [RFC] Variable Syntax Tweaks, [RFC] Static return type, [RFC] Allow ::class on objects
  • [RFC] Write-Once Properties β€” , , . , : final, immutable, readonly, writeonce, locked, sealed.
    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 forbidden
    unset($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
    

    . , , , , , .
  • [RFC] str_contains β€” str_contains(string $haystack , string $needle) :bool, , strpos() strstr().
  • [RFC] Object-based token_get_all() alternative β€” token_get_all(), PhpToken.
  • [RFC] get_debug_type β€” : gettype() get_class().
  • [RFC] Allow explicit call-site pass-by-reference annotation β€” RFC . . , . , .
    declare(require_explicit_send_by_ref=1);
    
    function byRef(&$ref) {...}
    byRef(&$var);
    
  • [Pre-RFC] Add support for Β«decoratorΒ» pattern β€” «» PHP.
    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 {
        private decorated Foo $inner;
        public function __construct(Foo $inner) { $this->inner = $inner; }
        public function method4(): stdClass {
            return $DO_SOMETHING_DIFFERENT_HERE;
        }
    }
    
    /*
       decorated,  ,    
          Foo,      
      .      ,  
       .
    */
    
  • [PR] Use serialize_precision for printing floats in var_dump() β€” , float var_dump() (0.1 + 0.2 === 0.30000000000000004):
    
    // 
    $sum = 0.1 + 0.2;
    var_dump($sum); // float(0.3)
    var_dump($sum == 0.3); // bool(false) WTF???
    
    // 
    $sum = 0.1 + 0.2;
    var_dump($sum); // float(0.30000000000000004)
    var_dump($sum == 0.3); // bool(false) Makes sense...
    



Symfony



Laravel



Yii



Async PHP





/



!

β€” , , .
.

Telegram- PHP Digest.

β€” GitHub.

← : PHP- β„– 173


All Articles