PHP Digest # 204 (May 17 - 31, 2021)

Photo: Christian MΓΌnch .



During these two weeks of the core, the PHP team actively discussed the proposal for a Partial function Application and, as an alternative, Nikita Popov suggested a simpler syntax for getting a link to any function. It is also proposed to add static properties to the enums already adopted in PHP 8.1.



Symfony 6 will require PHP 8.0, and the released Doctrine 2.9 supports specifying metadata in attributes instead of PHPDoc.



Also in the release is a cool article about regexps and instructions for using Deployer, as well as other useful articles, a pack of tools, some videos and podcasts.



Enjoy reading!





PHP Internals



  • [RFC] First-class callable syntax



    [RFC] Partial Function Application .



    //   
    $fn = Closure::fromCallable('strlen');
    $fn = Closure::fromCallable([$this, 'method']);
    $fn = Closure::fromCallable([Foo::class, 'method']);
    
    //   
    $fn = strlen(...);
    $fn = $this->method(...);
    $fn = Foo::method(...);
    
          
          







    , , callable



    . , :

    array_map(Something::toString(...), [1, 2, 3]);
    array_map(strval(...), [1, 2, 3]);
    
    // 
    array_map([Something::class, 'toString'], [1, 2, 3])
    array_map('strval', [1, 2, 3]);
    
          
          





  • [RFC] Disable autovivification on false



    PHP null



    false



    . false



    - Fatal error



    :

    $a = true;
    $a[] = 'value'; // Fatal error: Uncaught Error: Cannot use a scalar value as an array
    
    $a = null;
    $a[] = 'value'; // Ok
    
    $a = false;
    $a[] = 'value'; //   ,   
    
          
          



    3v4l.org/UucOC



  • [RFC] Allow static properties in enums



    PHP 8.1 . video PHP- php.watch.



    , .



    enum Environment {
        case DEV;
        case STAGE;
        case PROD;
    
        private static Environment $currentEnvironment;
    
        /**
         * Read the current environment from a file on disk, once.
         * This will affect various parts of the application.
         */
        public static function current(): Environment {
            if (!isset(self::$currentEnvironment)) {
                $info = json_decode(file_get_contents(__DIR__ . '/../../config.json'), true);
                self::$currentEnvironment = match($info['env']) {
                    'dev' => self::DEV,
                    'stage' => self::STAGE,
                    'prod' => self::PROD,
                };
            }
            return self::$currentEnvironment;
        }
        // Other methods can also access self::$currentEnvironment
    }
    printf("Current environment is %s\n", Environment::current()->name);
    
          
          





    . , .



    , PhpStorm 2021.2 enum



    , 2021.2 EAP.



  • [PR] HTTP Early Hint support



    , PHP . HTTP 1xx



    . , 103



    , Link, , , 200 OK



    .



    , : 103



    , , header()



    , β€” echo



    .



    , . - API Symfony HTTP.



  • check [RFC] Add IntlDatePatternGenerator



    . PHP 8.1 IntlDatePatternGenerator



    . PHP Internals News #85 RFC.



  • [RFC] Final class constants



    .



  • Internals bugs.php.net



    issues GitHub. , . , . PHP, issue php/doc-en php/doc-ru. .










Symfony







Laravel













/







community








Subscribe to the PHP Digest Telegram channel .



If you liked the digest, please give it a plus - this is very motivating to keep doing it.



Did you spot a mistake or typo? Inform in a personal habr or telegram .



You can send the link through the form or simply by writing to me in a telegram .

Search for links in all digests

← Previous issue: PHP-Digest # 203








All Articles