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!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I always prefer LTS versions, less bugs, less unexpected crap happening. But I would love to use PHP7.4 tought, especially Typed Variables.
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 examplewas perfectly legal but you never knew if $bar was a
Bar
ornull
.Now if I have
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:This then forces me to think when using
$this->bar
that the value could benull
and handle appropriately!