DEV Community

Pete McFarlane
Pete McFarlane

Posted on

PHP 7.4 in prod at last

This week we finally moved to PHP 7.4 in production at work. The upgrade has been the most anticipated (by me) since PHP 7.

The new hotness of short functions, typed properties, not to mention improved performance by file preloading, array spread syntax, null coalesce and a host of other improvements!

The only caveats we had upgrading were a few packages were fixed to PHP 7.3 (these have since been upgraded) and we require php-redis extension which is now installed with PECL.

Moving to production went fairly smoothly, to say we're still reliant on Chef and AWS Opsworks which both seem pretty outdated stacks for 2020 (hoping to move to containers soon!)

I really like the language improvements, feels like we're coming more mature as a language and taking inspiration from JavaScript, Java and others. It will be interesting to see the future development and what the future holds for PHP!

Have you upgraded yet? If so, what's your favourite new feature/improvement? If not, what's stopping you?!

Top comments (4)

Collapse
 
petemcfarlane profile image
Pete McFarlane

I think all versions of PHP are supported for 2 years now: php.net/supported-versions.php
I'm not sure any of them are LTS any more?
Typed properties are nice, I like that you have to be explicit if a property could also be null too, for example

class Foo
{
    /** @var Bar */
    private $bar;

    public function __construct(Bar $bar = null) 
    {
        $this->bar = $bar;
    }
}

was perfectly legal but you never knew if $bar was a Bar or null.

Now if I have

class Foo
{
    private Bar $bar;

    public function __construct(Bar $bar = null) 
    {
        $this->bar = $bar;
    }
}

it will throw a TypeError if I try to construct a new instance of Foo with a null value for $bar. To handle this I change the type to be ?Bar like so:

class Foo
{
    private ?Bar $bar;

    public function __construct(Bar $bar = null)
    {
        $this->bar = $bar;
    }
}

This then forces me to think when using $this->bar that the value could be null and handle appropriately!

Collapse
 
fr05t1k profile image
Stas Pavlovichev

I have problem with “segmentation fault” in php-fpm. I cannot reproduce it. It just happens sometimes. It’s defiantly related to opcache somehow. I hope I’ll manage manage with it🙂

Collapse
 
petemcfarlane profile image
Pete McFarlane

Oh dear, I used to have seg fault issues years ago upgrading to PHP 7.0, thankfully haven't had any since! Hope it gets resolved for you soon.