News

PHP Annotated – July 2022

PHP Annotated Monthly

Greetings everyone!

Welcome to the July installment of PHP Annotated, where we’ll catch up on the most interesting things that have happened in the PHP world over the last month, including curated news, articles, tools, and videos.

News

PHP Core

Most of the Core news is covered in detail in the PHP Core Roundup series from the PHP Foundation. The next episode of this series is coming soon, so we’ll only mention updates briefly:

  • RFC: Disjunctive Normal Form Types #PHP 8.2
    The support for Disjunctive Normal Form types has been approved for PHP 8.2. It will allow mixing union and intersection types.

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    class Foo {
    public function bar(): (A & B) | D;
    }
    class Foo { public function bar(): (A & B) | D; }
    class Foo {  
        public function bar(): (A & B) | D;
    }
    

    Learn more from Derick Rethan’s 🔈 PHP Internals News podcast Episode 103 with George Peter Banyard.

  • RFC: Fetch properties of enums in const expressions #PHP 8.2
    In PHP 8.2 it will be possible to use -> / ?-> to fetch properties of enums in constant expressions.

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    enum A: string {
    case B = 'B';
    const C = [self::B->value => self::B];
    }
    enum A: string { case B = 'B'; const C = [self::B->value => self::B]; }
    enum A: string {
        case B = 'B';
        const C = [self::B->value => self::B];
    }
    
  • RFC: Random Extension Improvement #PHP 8.2
  • RFC: Make the iterator_*() family accept all iterables #PHP 8.2.
    In PHP 8.2 the $iterator parameter of iterator_to_array() and iterator_count() will be widened from \Traversable to iterable (i.e. to \Traversable|array).

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    function foo(iterable $foo) {
    $foo = iterator_to_array($foo); //now accepts arrays
    return array_map(strlen(...), $foo);
    }
    function foo(iterable $foo) { $foo = iterator_to_array($foo); //now accepts arrays return array_map(strlen(...), $foo); }
    function foo(iterable $foo) {
        $foo = iterator_to_array($foo); //now accepts arrays
     
        return array_map(strlen(...), $foo);
    }
    
  • RFC: Constants in Traits #PHP 8.2
    In PHP 8.2 it will be possible to define constants in traits in the same manner that is currently possible for properties.

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    trait Foo {
    public const PHP_VERSION = '8.2';
    }
    class Base {
    use Foo;
    }
    class Bar extends Base {
    public function phpVersion(): void {
    echo parent::PHP_VERSION; // 8.2
    }
    }
    trait Foo { public const PHP_VERSION = '8.2'; } class Base { use Foo; } class Bar extends Base { public function phpVersion(): void { echo parent::PHP_VERSION; // 8.2 } }
    trait Foo {
        public const PHP_VERSION = '8.2';
    }
     
    class Base {
        use Foo;
    }
     
    class Bar extends Base {
        public function phpVersion(): void {
            echo parent::PHP_VERSION; // 8.2
        }
    }
    
  • RFC: New Curl URL API
  • RFC: json_encode indentation
  • RFC: Stricter implicit boolean coercions
  • RFC: Create a global login system for php.net
  • RFC: Short Closures 2.0
  • 🤔 RFC: Auto-implement Stringable for string backed enums
    This RFC proposes that string-backed enums auto-implement Stringable, while still disallowing userland implementations of the method.
  • 🤔 RFC: PDO driver specific sub-classes
  • 💡 RFC: Unify PHP’s typing modes (aka remove strict_type declare)
    A draft idea from George Peter Banyard to make strict_type the default in PHP (9+), along with consideration of its impact on type casting usage and developer burden.

Tools

Symfony

Laravel

Misc

Audio/Video

Community

That’s all for today – thanks for reading!

If you have any interesting or useful links to share via PHP Annotated, please leave a comment on this post or send me a tweet.

Subscribe to PHP Annotated

Your JetBrains PhpStorm team
The Drive to Develop

Roman Pronskiy

Product marketing manager for PhpStorm, helped to launch The PHP Foundation.

Twitter | GitHub

Sergey Panteleev

PHP 8.2 release manager, PHP Documentation maintainer.

Twitter | GitHub

image description