Skip to content

Commit d330c00

Browse files
bug #119 Update is_countable to include countable objects that doesn'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
2 parents b86307d + b53929e commit d330c00

File tree

4 files changed

+6
-1
lines changed

4 files changed

+6
-1
lines changed

Diff for: .travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ matrix:
1717
- php: 7.0
1818
- php: 7.1
1919
- php: 7.2
20+
- php: nightly
21+
allow_failures:
22+
- php: nightly
2023
fast_finish: true
2124

2225
before_install:

Diff for: src/Php73/bootstrap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
if (PHP_VERSION_ID < 70300) {
1313
if (!function_exists('is_countable')) {
14-
function is_countable($var) { return is_array($var) || $var instanceof Countable; }
14+
function is_countable($var) { return is_array($var) || $var instanceof Countable || $var instanceof ResourceBundle || $var instanceof SimpleXmlElement; }
1515
}
1616
}

Diff for: tests/Php73/Php73Test.php

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function testIsCountable()
2323
$this->assertTrue(is_countable(array(1, 2, '3')));
2424
$this->assertTrue(is_countable(new \ArrayIterator(array('foo', 'bar', 'baz'))));
2525
$this->assertTrue(is_countable(new \ArrayIterator()));
26+
$this->assertTrue(is_countable(new \SimpleXMLElement('<foo><bar/><bar/><bar/></foo>')));
27+
$this->assertTrue(is_countable(\ResourceBundle::create('en', __DIR__.'/fixtures')));
2628
$this->assertFalse(is_countable(new \stdClass()));
2729
}
2830

Diff for: tests/Php73/fixtures/en.res

316 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)