PHP Annotated – April 2023

PHP Annotated Monthly

Greetings everyone!

Welcome to the April installment of PHP Annotated, where we’ll catch up on the most exciting 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, so we’ll only list a few highlights:

  • RFC: Arbitrary static variable initializers
    PHP allows declaring static variables inside any functions. Their values outlive the function call and are shared across future execution of the function.

    In PHP 8.3, you can assign them any expression, e.g. the result of another function.

    function bar() {    
        echo "bar() called\n";
        return 1;
    }
     
    function foo() {
        static $i = bar();  // This currently produces a fatal error, but will work in PHP 8.3
        echo $i++, "\n";
    }
     
    foo();
    // bar() called
    // 1
    foo();
    // 2
    foo();
    // 3
    

    As a side effect, in PHP 8.3 redeclaring static variables will be forbidden. This will fix some PHP quirks that you have hopefully never seen in real code:

    <?php
    function f()
    {
      static $x = 1;
    
      return $x;
    
      static $x = 2;
    }
    echo f();
    

    If you expected the second static declaration to be unreachable, you’d unfortunately be mistaken: https://3v4l.org/HhpYj

  • 📣 RFC: Clone with
    Máté Kocsis proposed to add support for a new language construct called “clone with” by extending the clone operator, making it possible to write “wither” methods for any kind of instance properties (declared/dynamic, typed/untyped, readonly/non-readonly) with less code.

    Example
    class Response implements ResponseInterface {    public readonly int $statusCode;
        public readonly string $reasonPhrase;
        // ...
        public function withStatus($code, $reasonPhrase = ''): Response
        {
            return clone $this with {
                statusCode: $code,
                reasonPhrase: $reasonPhrase
            };
        }
        // ...
    }
    
    $response = new Response(200);
    $response->withStatus(201)->withStatus(202);
    
  • 📣 RFC: New core autoloading mechanism with support for function autoloading
    George Peter Banyard and Dan Ackroyd propose a better-designed class-autoloading mechanism, and add a new function-autoloading mechanism.
  • 📣 Jakub Zelenka proposes to form PHP Technical Committee
    PHP uses RFC voting to decide on user-visible language changes, which works well despite some known issues. However, it’s not as effective for technical changes that impact PHP internals and extension APIs, and conflicts between contributors on technical bases are not easily resolved.

    The proposed committee would consist of 5 elected members and, should a dispute or question about a change arise, the committee may be called on to resolve it.

Tools

  • crazywhalecc/static-php-cli – The tool for building PHP apps into a single binary file with no extra dependencies.
  • aschmelyun/subvert – Generate subtitles, summaries, and chapters from videos in seconds.
  • yiisoft/db – Framework-agnostic query builder for different types of databases (MariaDB, MSSQL, MySQL, Oracle, PostgreSQL, and SQLite).
  • Crell/EnvMapper – Easily map environment variables into defined classed objects, ready for dependency injection.
  • PHP Skeleton for Bison by Anton Sukhachev.
    The syntax of PHP and many other languages is described by grammar in Bison format. mrsuh/php-bison-skeleton makes it possible to generate a Bison parser in PHP without third-party dependencies.
  • 🚧 NativePHP
    Marcel Pociot is building a tool to run Laravel/PHP apps on desktop on top of Electron or Tauri.

Symfony

Laravel

  • Laravel Valet 4.0 released
    Despite the name, Laravel Valet is a minimalistic development environment for macOS that can be used for any PHP project.

    This release is mostly about rewriting the internals, so they’re easier to debug, fix, and modify. It also brings a new valet status command and supports Expose as a sharing option.

  • Laravel IDEA 7.0
    The popular plugin for PhpStorm has received a major update. It includes the “New Eloquent Model” UI and Twig templates support.

    Check out this video demo on Laravel Daily.

  • Build a ChatGPT clone using the new OpenAI Chat API by Marcel Pociot.
  • Everything You Can Test In Your Laravel Application by Christoph Rumpel – Excellent guide with examples of scenarios you’ll likely need to test on real applications.
  • TomasVotruba/bladestan – PHPStan analysis for Blade templates.
  • lunarphp/lunar – An open-source headless e-commerce package for Laravel. You have complete freedom to create your own storefront, but the backend work is already done for you.
  • area17/twill – A CMS toolkit for Laravel that helps rapidly create a custom admin console that is intuitive, powerful, and flexible.
  • 📺 Laravel Weekly Update #6 – The team now provides a weekly roundup of Laravel news and updates in short videos.

Misc

Community

  • In case you missed it, Brent and Roman are now doing a video version of PHP Annotated. Check out the latest installment and be sure to subscribe to the PHP Annotated YouTube channel.
  • PoPHPularity: Is it decreasing and what to do about it? by Christian Olear.
  • Modern PHP by Dimitrios Lytras – “While I wasn’t paying attention, PHP got quite good.”

Conferences

Check out these upcoming PHP gatherings worth visiting and applying to present at:


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

Subscribe
to PHP Annotated

Roman Pronskiy

Product marketing manager for @PhpStorm, had a hand in creation of @The PHP Foundation.

Twitter | GitHub

image description