Skip to content

Printer handles null value of Property as no value incorrectly  #71

@dakur

Description

@dakur

Version: 3.4.1

Bug Description

When printing class, there is this line:

($property->getValue() === null && !$property->isInitialized() ? '' : ' = ' . $this->dump($property->getValue(), strlen($def) + 3)) // 3 = ' = '

which basically means that if I set value of Property to null intentionally, this value is not printed.

Steps To Reproduce

E.g. $property->setPrivate()->setValue(null) generates private $property;
But $property->setPrivate()->setValue('test') generates private $property = 'test'; properly

Expected Behavior

It should generate private $property = null;

Possible Solution

Mark null state with some constant instead of null. So it would look something like this:

class Property
{
    public const NO_DEFAULT_VALUE = '$73aad02e-7f5a-4ef2-8cdd-0fd09e6d9863§'; // hopefully no one is going to pass this string as default value

    // ...
}

// in printer:
($property->getValue() === Property::NO_DEFAULT_VALUE && !$property->isInitialized() ? '' : ' = ' . $this->dump($property->getValue(), strlen($def) + 3)) // 3 = ' = '

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions