Skip to content

Conversation

@chadyred
Copy link
Contributor

@chadyred chadyred commented Mar 27, 2024

Hello,

I personally use the Countable "count" method of the ConstraintViolationListInterface

Thanks :)

@carsonbot carsonbot added this to the 7.1 milestone Mar 27, 2024
@carsonbot carsonbot changed the title [Validation] Check validation errors by using the OOP way [Validator] [Validation] Check validation errors by using the OOP way Mar 27, 2024
@javiereguiluz
Copy link
Member

Thanks Florian. I don't have a strong opinion about this, so let's wait for other opinions.

@smnandre
Copy link
Member

Classes implementing Countable can be used with the count() function.

https://www.php.net/manual/en/class.countable.php

If, in fact, to implements the Countable interface you do have to declare a count() method, it is an implementation thing, as the primary goal of Countable is to call count($object) ... allowing to count different types of data.

So as early developers see count() more often... i'd say it's better to stay at a higher level.

And they will not hesitate between count() and ->count when they do not know if the "thing" passed is an array or an object :)

Example:

// $foo can be an array or an object

if (is_countable($foo)) {
    return count($foo);
} 

@chadyred
Copy link
Contributor Author

chadyred commented Apr 1, 2024

Thanks for your time and your explanation @smnandre it is clear enough to close this PR ;)

@chadyred chadyred closed this Apr 1, 2024
@chadyred chadyred deleted the 7.1 branch April 1, 2024 13:45
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.

4 participants