Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3769052
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/Collections/TraversableUtilities.php b/src/Collections/TraversableUtilities.php
index 8d7921c..5877919 100644
--- a/src/Collections/TraversableUtilities.php
+++ b/src/Collections/TraversableUtilities.php
@@ -1,27 +1,33 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Collections;
use Countable;
+use ResourceBundle;
+use SimpleXMLElement;
use TypeError;
class TraversableUtilities {
public static function count ($countable) : int {
- if (is_array($countable)) {
+ if (self::isCountable($countable)) {
return count($countable);
}
- if ($countable instanceof Countable) {
- return $countable->count();
- }
-
if ($countable === null || $countable === false) {
return 0;
}
throw new TypeError;
}
+ public static function isCountable ($countable) : bool {
+ // https://github.com/Ayesh/is_countable-polyfill/blob/master/src/is_countable.php
+ return is_array($countable)
+ || $countable instanceof Countable
+ || $countable instanceof SimpleXMLElement
+ || $countable instanceof ResourceBundle;
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 25, 12:22 (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260160
Default Alt Text
(1 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment