I co-organise the BrisPHP Meetup and at the start of every meetup I give a quick talk on recent news and other interesting things that have been happening in the PHP world. This quater the biggest things have been PHP 7.3 and MySQL 8.0.

PHP 7.3

PHP 7.3 is just around the corner, with Beta 3 being released today, and final release due for December. You can check the release schedule here. This triggered me to check which versions of PHP are currently supported:

  • Both 5.6 and 7.0 our out of active support
    • Have security support until December this year
  • 7.1 has active support until December this year
  • 7.2 has active upport until November next year

One of the core PHP developers (Zeev Suraski) posted his thoughts about PHP 8, in which he mentions that 7.4 will likely be the final version in the 7.* release line that will only include deprecations allowing them to pave the way forward for PHP 8.

New features in 7.3

PHP 7.3 brings a huge list of changes and bug fixes, the best of which are summarised quite well by Tomas Votruba here, Here are my favourites in order of coolness:

  1. JSON_THROW_ON_ERROR - no longer will you have to check json_last_error() to handle json errors properly:
     <?php
    
     public function safeJsonDecode(string $json): array
     {
         $data = json_decode($json);
         if (JSON_ERROR_NONE === json_last_error()) {
             throw new \RuntimeException('Invalid JSON data!');
         }
    
         return $data;
     }
    
     try {
         $data = safeJsonDecode($myJsonData);
     } catch (\RuntimeException $e) {
         // Handle errors
     }
    

    Instead you can replace it with:

     <?php
    
     try {
         $data = json_decode($myJsonData, false, 512, JSON_THROW_ON_ERROR);
     } catch (JsonException $e) {
         // handle error
     }
    
  2. Trailing comma in function calls - very useful for clean git diffs on multi-line function calls (the same as multi-line array declarations):
     <?php
    
     $this->foo(
         $bar,
         $baz,
     );
    
  3. array_key_first() and array_key_last() - get the first and last values of an array:
     <?php
    
     $array = ['foos' => 1, 'bars' => 2, 'bazzes' => 3];
    
     $firstKey = array_key_first($array);
     $lastKey = array_key_last($array);
    
     echo $firstKey // 'foos'
     echo $lastKey // 'bazzes'
    
  4. Better heredoc - meaning you don’t have to break your indentation to use heredoc:
     <?php
    
     class AnimalSentences
     {
            
         public function jumpLazyFox(string $animal): string
         {
             $foo = <<<EOF
             the crazy "%s"
                 jumps over the lazy fox;
             EOF
    
             return sprintf($foo, $animal);
         }
     }
    

MySQL jumped 2 major version numbers

That’s right, MySQL has gone from 5.7 to 8.0! Apparently version 6 was too ambitious so it got canned (much like PHP 6 😂) and the number 7 was already being used by MySQL cluster.

Version 8.0 was released in April, which again caused me to check the EOL for previous versions:

  • 5.7: October 2023
  • 5.6: Februrary 2021
  • 5.5: December this year
  • All other versions are unsuppported

New features in 8.0

There is a certifiably gigantor list of new and removed features in 8.0, and has been written about in many places. Here are my favourites in order of coolness:

  • Document store
    • Full NoSQL in MySQL built on top of InnoDB
    • Take full advantage of both SQL and NoSQL at once
  • JSON_TABLE() takes JSON data and outputs a relational table
    • The results of which can be used in SQL like a regular table
  • Instant add column, no matter the size of the table
  • Role Based Access Control
    • You can group privileges into roles and assign the roles to a user instead of adding individual privileges to each user
  • Default character set is utf8mb4 (ie. the real UTF-8)
    • Now you can store 💩 without having to manually set the character set of each table
  • Default values can now be expressions
  • Invisible indexes
    • You can test adding and removing indexes without actually affeting the optimizer
  • UUID’s can be stored as binary and converted to strings on the fly

PSR-17 was accepted

PSR-17, is closely related to PSR-7, which defines the interface how HTTP messages (ie. Requests and Responses). PSR-17 defines the interfaces for the factories that construct PSR-7 messages.

Laravel

Security release

Versions 5.6.30 and 5.5.42 were released to patch a security vulnerability which allows a malacious party to attack your application if they know your APP_KEY environment variable.

Nova was released

Laravel Nova was released, which is a paid administration panel service by Taylor Otwell.