Skip to content

Commit

Permalink
Update is_countable to include countable objects that doesn't impleme…
Browse files Browse the repository at this point in the history
…nt \Countable
  • Loading branch information
pierredup committed Apr 25, 2018
1 parent 8d09841 commit b53929e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Php73/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
if (PHP_VERSION_ID < 70300) {
if (!function_exists('is_countable')) {
function is_countable($var) {
return is_array($var) || $var instanceof Countable;
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 @@ -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')));
$this->assertFalse(is_countable(new \stdClass()));
}

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

0 comments on commit b53929e

Please sign in to comment.