Skip to content
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

Update is_countable to include countable objects that doesn't implement \Countable #119

Merged
merged 1 commit into from
Apr 26, 2018

Conversation

pierredup
Copy link
Contributor

Some objects are countable but don't implement Countable (symfony/polyfill#115#issuecomment-384361414)

The objects that I could identify that is countable is ResourceBundle and SimpleXmlElement

@carusogabriel
Copy link
Contributor

@pierredup Is there any way to find all of then?

@pierredup
Copy link
Contributor Author

I used https://github.com/php/php-src/search?utf8=✓&q=count_elements&type= as a simple check, which should cover everything in core. The other items found in the result (SplHeap, DoublyLinkedList, SplFixedArray etc) already implement Countable

@nicolas-grekas
Copy link
Member

Thank you @pierredup.

@nicolas-grekas nicolas-grekas merged commit b53929e into symfony:master Apr 26, 2018
nicolas-grekas added a commit that referenced this pull request Apr 26, 2018
…t implement \Countable (pierredup)

This PR was merged into the 1.8-dev branch.

Discussion
----------

Update is_countable to include countable objects that doesn't implement \Countable

Some objects are countable but don't implement `Countable` ([#115#issuecomment-384361414](#115 (comment)))

The objects that I could identify that is countable is `ResourceBundle` and `SimpleXmlElement`

Commits
-------

b53929e Update is_countable to include countable objects that doesn't implement \Countable
@pierredup pierredup deleted the update-is_countable branch April 26, 2018 06:36
@@ -26,6 +26,8 @@ public function testIsCountable()
$this->assertTrue(is_countable(array(1, 2, '3')));
$this->assertTrue(is_countable(new \ArrayIterator(array('foo', 'bar', 'baz'))));
$this->assertTrue(is_countable(new \ArrayIterator()));
$this->assertTrue(is_countable(new \SimpleXMLElement('<foo><bar/><bar/><bar/></foo>')));
$this->assertTrue(is_countable(\ResourceBundle::create('en', __DIR__.'/fixtures')));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need class_exists() calls for these two to make sure intl and xml extensions are loaded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Travis the extensions are loaded so the classes should always exist. In the actual polyfill, the check would just return false if the extension isn't loaded and the class doesn't exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants