-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
RFC: Counting of non-countable objects #2185
Conversation
IMO, tests shouldn't suppress warnings; you never know which warnings you might suppress inadvertently. And please have a look at the failing tests reported by Travis. At least some of these failures are caused by the new warnings. |
@cmb69 Agreed, what would you suggest we do? Adding the warnings into the expected output of some of those tests makes them unmanageable in my opinion. Sorry I checked Travis earlier and didn't think any were related, I'll look again 👍 |
204eb15
to
67d370d
Compare
Not sure what to do, but we may consider to change these tests. Perhaps splitting these PHPTs is an option. |
@@ -1637,7 +1637,7 @@ function run_test($php, $file, $env) | |||
$IN_REDIRECT['dir'] = realpath(dirname($file)); | |||
$IN_REDIRECT['prefix'] = trim($section_text['TEST']); | |||
|
|||
if (count($IN_REDIRECT['TESTS']) == 1) { | |||
if (is_array($IN_REDIRECT['TESTS']) && count($IN_REDIRECT['TESTS']) == 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.
It seems that this change lets several (PDO) tests fail.
67d370d
to
9483c13
Compare
@duncan3dc The tests should have the new warnings added to expected output, and should not suppress anything. |
@krakjoe I think it's fine to suppress the warning for the sizeof() tests, as the emission of the warning is already tested for the alias count(). For the exif, filter, xml tests I would suggest to rewrite the test so it no longer emits a warning. The warning is a result of bad test code, not something that the test explicitly tests. |
We may consider to remove the sizeof() tests altogether in favor of solely testing count(). |
I've noticed a small discrepancy between the RFC and this implementation. The RFC states:
However, the implementation (IMO rightly) also allows internal classes which do not implement Countable, but implement a count_elements handler, such as SimpleXMLElement. That would have to be documented, and it should also be documented which classes implement a count_element handler. |
Doesn't that make it impossible in userland to know when |
9483c13
to
5214f0d
Compare
AFAIK, no.
That would probably the cleanest solution, but what about existing classes that we don't control (i.e. PECL or even private)? Maybe we should add something like is_countable().
Done with 1ccada3. |
e2af022
to
259db22
Compare
"true" => true, | ||
"false" => false, | ||
"object" => (object) [], | ||
"simplexml" => new SimpleXMLElement("<xml><tag1></tag1><tag2></tag2></xml>"), |
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 know why it's using this class, but it's a bit strange to have a standard test bound to simplexml, which isn't always loaded.
Could we maybe find some other object with the same behaviour ?
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.
Some of the SPL classes (e.g. ArrayObject and SplFixedArray) also implement count_elements, and are always available as of PHP 5.3.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.
Thanks @cmb69, I'll take a look
cb31777
to
2de372f
Compare
0fd7bc1
to
34e43c3
Compare
Comment on behalf of krakjoe at php.net: Merged |
This breaks lots of thing when upgrading |
The |
Implementation for the recently accepted rfc: https://wiki.php.net/rfc/counting_non_countables
I've added new tests (
count_invalid.phpt
) to ensure all non-countables issue a warning.For existing tests I've either hidden warnings (because there were too many) or added expectations where warnings were already in use. I'm not sure of the usual approach here?