Nette fully supports PHP 7.4. What does it mean?

4 years ago by David Grudl  

Just a few days ago PHP 7.4 was born. This version is another important milestone in language development. The great news is that the Nette Framework is thoroughly prepared and fully tested with the new version. And beware, this applies not only to the current version 3.0 but also to the previous version 2.4.

If you want to take advantage of all the PHP 7.4 features, such as typed properties, nothing prevents you. Just call composer update :-)

When I mentioned typed properties, their support can be found in the new version of PHP Generator:

$class = new Nette\PhpGenerator\ClassType('Demo');

$class->addProperty('items')
	->setType('array')
	->setNullable()
	->setInitialized();

echo $class;

Result:

class Demo
{
	public ?array $items = null;
}

You can now also print anonymous functions in an abbreviated form called arrow functions:

$closure = new Nette\PhpGenerator\Closure;
$closure->setBody('return $a + $b;');
$closure->addParameter('a');
$closure->addParameter('b');

echo (new Nette\PhpGenerator\Printer)->printArrowFunction($closure);

Result:

fn ($a, $b) => $a + $b;

User input validation tool called Nette Schema, supports typed properties since it arrived on the scene, along with the launch of Nette 3 in April 2019:

class Config
{
	public string $dsn;
	public ?string $user;
	public ?string $password;
	public bool $debugger = true;
}

$schema = Nette\Schema\Expect::from(new Config);

Finally, you can use typed properties to inject dependencies into presenters:

class ArticlePresenter extends Nette\Application\UI\Presenter
{
	/** @inject */
	public Facade $facade;

How do you look forward to the new version of PHP?

Comments (RSS)

  1. Hi! Nice work ;)
    Is there any support for PHP 7.4 preloading?

    4 years ago

Sign in to submit a comment