JMSSerializerBundle
JMSSerializerBundle copied to clipboard
PHP 7.2: count(): Parameter must be an array or an object that implements Countable
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
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.
(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 ?
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.
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 ?
Do not know it the error was thrown for that reason... I think the error was in $entryName.. wasn't?
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.
There's no contributing guide in this repo, I would like to help on this one but I need something to follow
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
Please note that most likely you will have to submit your PR to the 1.x branch.