JMSSerializerBundle icon indicating copy to clipboard operation
JMSSerializerBundle copied to clipboard

PHP 7.2: count(): Parameter must be an array or an object that implements Countable

Open vasilvestre opened this issue 7 years ago • 9 comments

Similar to this issue : https://github.com/yiisoft/yii/issues/4167

The default behaviour of count changed, it now fire a warning. It happen for example here : https://github.com/schmittjoh/serializer/blob/1.x/src/JMS/Serializer/XmlDeserializationVisitor.php#L179

- if (!\count($nodes)) {
+ if ($nodes === false || !\count($nodes)) {

Or whatever condition we choose, to keep the default Serializer behaviour the check is needed

vasilvestre avatar Oct 09 '18 11:10 vasilvestre

This issue is not related to PHP 7.2 and neither to yiisoft/yii#4167. It is more related to DX.

The error is thrown because of some wrong syntax in $entryName.

In this case the solution is to throw an exception in $nodes === false and probably in the error message mentioning the value of $entryName.

goetas avatar Oct 09 '18 11:10 goetas

(Link to yii was just to give another case of the problem in another case)

So if it's false, an error have to be thrown ?

vasilvestre avatar Oct 09 '18 11:10 vasilvestre

So if it's false, an error have to be thrown ?

yes. there is no right "default" behavior the lib could do except of throwing an error.

goetas avatar Oct 09 '18 11:10 goetas

I don't know, it's supposed to throw an error if the node is empty ? Isn't it a problem of code logic or content ?

vasilvestre avatar Oct 09 '18 12:10 vasilvestre

Do not know it the error was thrown for that reason... I think the error was in $entryName.. wasn't?

goetas avatar Oct 09 '18 12:10 goetas

After a short discussion, I think @goetas decided that if the xpath function return false ($nodes is the xpath return) then an exception have to be thrown.

vasilvestre avatar Oct 09 '18 13:10 vasilvestre

There's no contributing guide in this repo, I would like to help on this one but I need something to follow

vasilvestre avatar Oct 11 '18 06:10 vasilvestre

You have created the ticker in the wrong repo :) (that's why I have added the "serializer issue" label)

The ticket should have been opened on https://github.com/schmittjoh/serializer. Into that library you have https://github.com/schmittjoh/serializer/blob/master/CONTRIBUTING.md as contributing guide

goetas avatar Oct 11 '18 07:10 goetas

Please note that most likely you will have to submit your PR to the 1.x branch.

goetas avatar Oct 11 '18 07:10 goetas