Home » Php » php 7.4 – PHP typed properties bulk declare can't assign null to nullable field

php 7.4 – PHP typed properties bulk declare can't assign null to nullable field

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have stamp over counterintuitive bug/property.

class xxx{
    public ?int $a, $b;

    public function __construct($a, $b){
        $this->a = $a;
        $this->b = $b;
    }
}

new xxx(null, 10); //Working
new xxx(10, null); //Not working

Can someone explain to me why the second line is not working.

PHP version 7.4.2.

How to&Answers: