diff --git a/rules-tests/CodingStyle/Rector/Assign/ManualJsonStringToJsonEncodeArrayRector/Fixture/null_item.php.inc b/rules-tests/CodingStyle/Rector/Assign/ManualJsonStringToJsonEncodeArrayRector/Fixture/null_item.php.inc new file mode 100644 index 00000000000..e1656bd2b98 --- /dev/null +++ b/rules-tests/CodingStyle/Rector/Assign/ManualJsonStringToJsonEncodeArrayRector/Fixture/null_item.php.inc @@ -0,0 +1,28 @@ + +----- + null]; + $json = \Nette\Utils\Json::encode($jsonData); + } +} + +?> diff --git a/src/PhpParser/Node/NodeFactory.php b/src/PhpParser/Node/NodeFactory.php index 3321634ff91..6421281daef 100644 --- a/src/PhpParser/Node/NodeFactory.php +++ b/src/PhpParser/Node/NodeFactory.php @@ -595,7 +595,7 @@ private function createArrayItem($item, string | int | null $key = null): ArrayI $arrayItem = new ArrayItem($this->createArray($item)); } - if ($item instanceof ClassConstFetch) { + if ($item === null || $item instanceof ClassConstFetch) { $itemValue = BuilderHelpers::normalizeValue($item); $arrayItem = new ArrayItem($itemValue); }