What's new in PHP land? Q1 2022

@brisphp1

https://brisphp.com

#BrisPHP

@brisphp1

https://brisphp.com

#BrisPHP

PHP Version Stats

@brisphp1

https://brisphp.com

#BrisPHP

PHP Version Stats

@brisphp1

https://brisphp.com

#BrisPHP

PHP Foundation Update

@brisphp1

https://brisphp.com

#BrisPHP

PHP Foundation Update

Sponsored developers

@brisphp1

https://brisphp.com

#BrisPHP

PHP Foundation Update

  • Implement development processes
  • Improve maintenance and user-focused features
  • Reduce bus factor by updating PHP Internals book

Next goals

@brisphp1

https://brisphp.com

#BrisPHP

PHP 8.2: Null & False types

class User {}
 
interface UserFinder
{
    function findUserByEmail(): User|null;
}
 
class AlwaysNullUserFinder implements UserFinder
{
    function findUserByEmail(): null
    {
        return null;
    }
}

@brisphp1

https://brisphp.com

#BrisPHP

PHP 8.2: Null & False types

class Trade {}

class Project {
    /** @var Trade[] */
    public array $trades;
}
 
interface ProjectRelatedInterface
{
    function getProject(): Project;
    function getTrade(): Trade|null;
}
 
class EditProjectEvent implement ProjectRelatedInterface {
    public function getProject(): Project {...}
    public function getTrade(): null {return null}
}

@brisphp1

https://brisphp.com

#BrisPHP

PHP 8.2: Locale independent case conversion

  • Locale sensitivity is almost always a bug
  • Case conversion only really makes sense for ASCII (a-z|A-Z)
  • Ignore non-ASCII characters

@brisphp1

https://brisphp.com

#BrisPHP

PHP 8.2: Deprecate partially supported callables

// Some callables are supported by call_user_func() 
// but not $callable()

// Change to the following syntax
"self::method"       -> self::class . "::method"
"parent::method"     -> parent::class . "::method"
"static::method"     -> static::class . "::method"
["self", "method"]   -> [self::class, "method"]
["parent", "method"] -> [parent::class, "method"]
["static", "method"] -> [static::class, "method"]

// Can also use PHP 8.1 syntax
self::method(...) 

@brisphp1

https://brisphp.com

#BrisPHP

PHP 8.2: Deprecate dynamic properties

class User {
    public $name;
}
 
$user = new User;
 
// Assigns declared property User::$name.
$user->name = "foo";
 
// Oops, a typo:
$user->nane = "foo";
// PHP <= 8.1: Silently creates dynamic property.
// PHP    8.2: Raises deprecation warning
// PHP    9.0: Throws Error exception.

// Add #[AllowDynamicProperties] if necessary

@brisphp1

https://brisphp.com

#BrisPHP

PHP 8.2: Remove libmysql from mysqli

  • libmysql and mysqlnd are bindings for mysql and PDO
  • mysqlnd recommended since 5.4
  • libmysql has worse performance and memory management
  • mysqlnd is bundled with php
  • libmysql still available with PDO

@brisphp1

https://brisphp.com

#BrisPHP

PHP 9.0: Undefined error promotion

 if ($user->admin) { 
    $restricted = false;
 }
 
 // Oops, not defined
 if ($restricted) { 
    die('You do not have permission to be here');
 }
 
 $name = 'Joe';
 // Oops, typo
 echo 'Welcome, ' . $naame;
  • PHP < 8.0: Notice
  • PHP 8.*: Warning
  • PHP 9.0: Error Exception

@brisphp1

https://brisphp.com

#BrisPHP

Laravel 9

  • 12 monthly releases instead of 6 monthly (timed with Symfony)
  • PHP 8.0 minimum version
  • Symfony mailer integration
  • Flysystem 3.x
  • Eloquent enum support
  • Route binding enums

Questions?

@brisphp1

https://brisphp.com

#BrisPHP

What's new in PHP land - Q2 2022

By Nathan Dench

What's new in PHP land - Q2 2022

  • 241