Skip to content

Handling of nulls when applying defaults #377

Closed
@gtuccini

Description

@gtuccini

Currently null default values are not correctly applied. I think this happens because validateCommonProperties, in UndefinedConstraint.php, uses isset to check whether a default value has been defined and it cannot distinguish between a null default value and an undefined one.

// e.g.
if (!$this->getTypeCheck()->propertyExists($value, $i) && isset($propertyDefinition->default)) {

Moreover, when the subject is an array and default properties or items have been defined, non-null default values are applied even if the properties or the items have a null value. Again, I think this happens because the code uses isset to check whether the property or the item exists.

if (!isset($value[$i]) && isset($propertyDefinition->default)) {
// ...
if (!isset($value[$i]) && isset($itemDefinition->default)) {

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