-
-
Notifications
You must be signed in to change notification settings - Fork 468
Resolves Problem with PHP 7.2 Throwing Error on count #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Problem: Currently PHP 7.2 throws an error if count is used on a non-countable object. Resolution: Check for variable Countableness. Change: Check variable is an instanceof Countable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your changes change the semantics of the comparison, making the conditions always false
. I suggested alternatives below.
{ | ||
// XPath index | ||
if (count($rule['tag']) > 0 && | ||
if ($rule['tag'] instanceof Countable && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$rule['tag']
is compared with a string below, so this check is incorrect. I suggest checking against !empty
instead of count
.
if (count($rule['tag']) > 0 && | ||
if ($rule['tag'] instanceof Countable && | ||
count($rule['tag']) > 0 && | ||
$rule['key'] instanceof Countable && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$rule['key']
is compared with an int below, so this check is incorrect as well. Since it's supposed to be an index, I'd suggest to check $rule['key'] > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why the original implementation would use count on strings or integers as opposed to arrays which it was designed for, is there a reason why?
Neither do I - especially since Unfortunately, it looks like there hasn't been any activity here for quite some time. @paquettg are you still maintaining this package? If not, would you consider somebody else to take over basic maintenance? |
I would love to see this issue resolved as it is breaking my applications. |
Is anybody will apply that PR? |
Can anyone fork and apply the PR ? |
@paquettg could you please merge this PR as your bundle is actually not compatible with PHP 7.2 |
I've tried reaching @paquettg a while ago, with no success. Thus, I've decided to create a fork and provide basic support for it: https://github.com/thesoftwarefanatics/php-html-parser. Basic support means: we'll be fixing issues if they affect whatever we need of the library and we'll merge pull requests other contributors create. No active development is taking place - we're merely ensuring a dependency still works as it's supposed to. Whether you're directly requiring this dependency or you're just getting it through another dependency, you can use this forked version by adding |
Thanks @alcaeus. Lifesaver. |
@alcaeus thanks a bunch! |
Problem: Currently PHP 7.2 throws an error if count is used on a non-countable object.
Resolution: Check for variable Countableness.
Change: Check variable is an instanceof Countable.