News

PHP Annotated – September 2024

PHP Annotated

Welcome to the September edition of PHP Annotated! After a brief summer break, we’re back with all things PHP. This recap is carefully handcrafted and brings you the most interesting developments in the PHP community over the past couple of months, so you don’t have to sift through the noise—we’ve done it for you.

Highlights

PHP Core

  • RFC: Asymmetric Visibility v2 💜

    Thanks to Ilija Tovilo’s and Larry Garfield’s proposal, PHP 8.4 will have asymmetric visibility, i.e. possibility to make properties public for reading (get) and private for changing (set). The syntax was inspired by Swift.

  • RFC: Lazy Objects 💜

    Lazy objects are standard objects except that their initialization is deferred until one of their properties is accessed (including non-existing ones). This can be useful
    Arnaud Le Blanc and Nicolas Grekas successfully implemented this addition to PHP 8.4.

    Very likely, the lazy objects won’t be used directly by most PHP users, but package and framework authors will benefit from it a lot as it allows them to remove a lot of boilerplate code. Here is for example how symfony/var-exporter will be simplified:

  • RFC: Transform exit() from a language construct into a standard function 💜

    Gina Peter Banyard proposed to make exit() a proper function with the following signature: function exit(string|int $status = 0): never {}

    The benefit is that it will properly validate the arguments passed and throw a TypeError if you pass something irrelevant, such as an array or resource.

  • 📣 RFC: Improve language coherence for the behaviour of offsets and containers 💜

    PHP supports offset accesses using brackets [] with the following notation $container[$offset]. However, the behavior of such accesses depends not only on the container type and offset, but also on the operation that is performed when accessing the offset. The existing behavior is highly inconsistent and difficult to predict.

    Gina Peter Banyard proposes to improve language consistency for offsets and containers.

  • 📣 RFC: Function Autoloading v4

    Robert Landers proposes to add the ability to autoload functions by adding a 4th parameter to spl_autoload_register(…). Then with a simple PSR-4-like autoloader for functions, the code example could look like this:

    spl_autoload_register(function ($function_name) {...}, false, false, SPL_AUTOLOAD_FUNCTION);   
    

    There is an alternative more comprehensive proposal from Gina P. Banyard: RFC: New core autoloading mechanism with support for function autoloading.

  • 📣 RFC: Default expression

    Paul Morris proposes to introduce the default expression in argument-passing contexts to use the default value of the function or method.

    function greetingEveryone($greeting = 'Hello', $subject = 'World') {  
        return sprintf('%s, %s!', $greeting, $subject);  
    }  
    
    echo greetingEveryone(default, ‘Earth’)); // Hello, Earth!  
    

    A similar proposal has been declined in the past, and it seems the problem has already been solved with the named arguments

Tools

AI

Symfony

Laravel

Other Frameworks

Misc

Conferences

These PHP events are all worth a visit, and some are still accepting presentation proposals:

To find a PHP meetup happening near you, check out the calendar on php.net.

Fun

  • JavaScript Bloat in 2024 by Niki Tonsky – “Gitlab needs 13 MB of JS code just to display a static landing page.”


If you have any interesting or useful links to share via PHP Annotated, please leave a comment on this post or let us know on X/Twitter.

Subscribe to PHP Annotated

Roman Pronskiy

Developer Advocate at @PhpStorm, Operations Manager at @The PHP Foundation.

Twitter | GitHub

image description