Bug Report
| Subject |
Details |
| Rector version |
0.17.1 |
| Installed as |
composer dependency |
Minimal PHP Code Causing Issue
See https://getrector.com/demo/0edaff43-96f2-413b-952c-c0c8197f999b
<?php
use DateTime;
use Doctrine\ORM\Mapping as ORM;
final class DemoFile
{
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected ?DateTime $date = null;
public function __construct()
{
}
}
Responsible rules
MoveCurrentDateTimeDefaultInEntityToConstructorRector
Actual Behavior
<?php
use DateTime;
use Doctrine\ORM\Mapping as ORM;
final class DemoFile
{
/**
* @ORM\Column(type="datetime", nullable=true)
*/
- protected ?DateTime $date = null;
+ protected ?DateTime $date;
public function __construct()
{
}
}
Expected Behavior
My expectation is that the code remains unchanged because nullable typed properties without default value, in this case null, leads to the error "Typed property ... must not be accessed before initialization". Or at least adds initialization with null in the constructor.
Bug Report
Minimal PHP Code Causing Issue
See https://getrector.com/demo/0edaff43-96f2-413b-952c-c0c8197f999b
Responsible rules
MoveCurrentDateTimeDefaultInEntityToConstructorRectorActual Behavior
Expected Behavior
My expectation is that the code remains unchanged because nullable typed properties without default value, in this case null, leads to the error "Typed property ... must not be accessed before initialization". Or at least adds initialization with null in the constructor.