-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Promote count() warning to TypeError #4572
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
b9d67f0
to
7a898c6
Compare
Will look into the test failure after I've split up the PR into separate smaller ones. |
7a898c6
to
f885924
Compare
I'm unsure about this one. One on hand this is a pretty clear case where TypeError should be thrown. On the other hand we do know that the introduction of this warning had some major fallout (possibly one of the largest BC impacts overall in the whole 7.x series), so we might need to be more careful here. |
Should I raise this issue on internals and see the feedback which comes with it? I would say this is inline with your TypeError RFC. |
I can see how initially introducing the warning was a large BC break, but it doesn't seem like converting it to an exception is nearly so disruptive. No more than the many other warnings being converted per the consistent type errors RFC. |
@@ -1861,8 +1861,11 @@ function run_test($php, $file, $env) | |||
} | |||
|
|||
} else { | |||
|
|||
if (!isset($section_text['PHPDBG']) && @count($section_text['FILE']) + @count($section_text['FILEEOF']) + @count($section_text['FILE_EXTERNAL']) != 1) { |
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.
Personally I'd just replace these @count()
with isset()
.
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.
Replacing with isset()
would change the logic of this condition as the usage of count()
here is to assert that ONLY one of the sections is present otherwise the test file is bogus, same below.
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.
To be clear, this is what I had in mind:
if (!isset($section_text['PHPDBG']) && @count($section_text['FILE']) + @count($section_text['FILEEOF']) + @count($section_text['FILE_EXTERNAL']) != 1) { | |
if (!isset($section_text['PHPDBG']) && isset($section_text['FILE']) + isset($section_text['FILEEOF']) + isset($section_text['FILE_EXTERNAL']) != 1) { |
Too dirty?
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.
Hum, the intention of this is kinda lost, I'll probably have a look at it again later and try to see if I can't refactor the codebase a bit better.
@@ -34,5 +34,5 @@ int(3) | |||
0 => 0 | |||
1 => 10 | |||
2 => 20 | |||
FFI\Exception: Attempt to count() on non C array | |||
TypeError: Parameter must be an array or an object that implements 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.
Hm, why does this change? That seems odd.
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.
Should be fixed by d266ba4.
@@ -735,7 +735,7 @@ PHPAPI zend_long php_count_recursive(HashTable *ht) /* {{{ */ | |||
|
|||
if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) { | |||
if (GC_IS_RECURSIVE(ht)) { | |||
php_error_docref(NULL, E_WARNING, "recursion detected"); | |||
zend_throw_error(NULL, "Recursion detected"); |
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 wouldn't change this. Just skip and return null then.
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.
ACK
We discussed this in R11, some points:
Overall, I believe the consensus was against merging this change, though not everyone agreed (in particular @markrandall). Some people we in favor of dropping the warning for |
Split from #4566