Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8.1k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't change this. Just skip and return null then. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ACK | ||
| return 0; | ||
| } | ||
| GC_PROTECT_RECURSION(ht); | ||
| @@ -773,7 +773,7 @@ PHP_FUNCTION(count) | ||
| switch (Z_TYPE_P(array)) { | ||
| case IS_NULL: | ||
| php_error_docref(NULL, E_WARNING, "Parameter must be an array or an object that implements Countable"); | ||
| zend_type_error("Parameter must be an array or an object that implements Countable"); | ||
| RETURN_LONG(0); | ||
| break; | ||
| case IS_ARRAY: | ||
| @@ -804,12 +804,12 @@ PHP_FUNCTION(count) | ||
| } | ||
| /* If There's no handler and it doesn't implement Countable then add a warning */ | ||
| php_error_docref(NULL, E_WARNING, "Parameter must be an array or an object that implements Countable"); | ||
| zend_type_error("Parameter must be an array or an object that implements Countable"); | ||
| RETURN_LONG(1); | ||
| break; | ||
| } | ||
| default: | ||
| php_error_docref(NULL, E_WARNING, "Parameter must be an array or an object that implements Countable"); | ||
| zend_type_error("Parameter must be an array or an object that implements Countable"); | ||
| RETURN_LONG(1); | ||
| break; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --TEST-- | ||
| Test count() function error conditions | ||
| --FILE-- | ||
| <?php | ||
| /* Prototype: int count ( mixed $var [, int $mode] ); | ||
| Description: Count elements in an array, or properties in an object | ||
| */ | ||
| try { | ||
| count(NULL, COUNT_NORMAL); | ||
| } catch (\TypeError $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
| try { | ||
| count(NULL, COUNT_RECURSIVE); | ||
| } catch (\TypeError $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
| try { | ||
| count(NULL); | ||
| } catch (\TypeError $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
| try { | ||
| count("string", COUNT_NORMAL); | ||
| } catch (\TypeError $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
| try { | ||
| count("string", COUNT_RECURSIVE); | ||
| } catch (\TypeError $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
| try { | ||
| count("string"); | ||
| } catch (\TypeError $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
| try { | ||
| count(""); | ||
| } catch (\TypeError $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
| try { | ||
| count(100); | ||
| } catch (\TypeError $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
| try { | ||
| count(-23.45); | ||
| } catch (\TypeError $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
| try { | ||
| @count($a); | ||
| } catch (\TypeError $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
| ?> | ||
| --EXPECT-- | ||
| Parameter must be an array or an object that implements Countable | ||
| Parameter must be an array or an object that implements Countable | ||
| Parameter must be an array or an object that implements Countable | ||
| Parameter must be an array or an object that implements Countable | ||
| Parameter must be an array or an object that implements Countable | ||
| Parameter must be an array or an object that implements Countable | ||
| Parameter must be an array or an object that implements Countable | ||
| Parameter must be an array or an object that implements Countable | ||
| Parameter must be an array or an object that implements Countable | ||
| Parameter must be an array or an object that implements Countable |
Uh oh!
There was an error while loading. Please reload this page.
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.