Skip to content

Commit

Permalink
bug #119 Update is_countable to include countable objects that doesn'…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
nicolas-grekas committed Apr 26, 2018
2 parents b86307d + b53929e commit d330c00
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ matrix:
- php: 7.0
- php: 7.1
- php: 7.2
- php: nightly
allow_failures:
- php: nightly
fast_finish: true

before_install:
Expand Down
2 changes: 1 addition & 1 deletion src/Php73/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

if (PHP_VERSION_ID < 70300) {
if (!function_exists('is_countable')) {
function is_countable($var) { return is_array($var) || $var instanceof Countable; }
function is_countable($var) { return is_array($var) || $var instanceof Countable || $var instanceof ResourceBundle || $var instanceof SimpleXmlElement; }
}
}
2 changes: 2 additions & 0 deletions tests/Php73/Php73Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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')));
$this->assertFalse(is_countable(new \stdClass()));
}

Expand Down
Binary file added tests/Php73/fixtures/en.res
Binary file not shown.

0 comments on commit d330c00

Please sign in to comment.