Skip to content

Conversation

@nicolas-grekas
Copy link
Member

Q A
Branch? 5.1
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

As spotted by @stof in #31466 (comment)

@xabbuh
Copy link
Member

xabbuh commented May 19, 2020

I think we should also throw a TypeError if one calls the method with null as the first argument followed by some constraints.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented May 19, 2020

If we don't allow null, it means the signature cannot be expressed using regular PHP types and we must trick it using func_num_args(). I think we'd better avoid such things.

$constraints = \func_get_args();
$validator = null;
} elseif (null !== $constraintOrValidator && !$constraintOrValidator instanceof ValidatorInterface) {
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a "%s" or a "%s" object, "%s" given.', __METHOD__, Constraint::class, ValidatorInterface::class, get_debug_type($constraintOrValidator)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message should say or "null" too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to advertise this case IMHO

@nicolas-grekas nicolas-grekas merged commit 0fd5b95 into symfony:5.1 May 19, 2020
@nicolas-grekas nicolas-grekas deleted the v-cb branch May 26, 2020 06:59
@fabpot fabpot mentioned this pull request May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants