3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class CountHelper { public static function count_if_you_can($var) { if (is_array($var)) { return count($var); } elseif (is_object($var)) { if ($var instanceof Countable) { return count($var); } else { return 1; } } elseif ($var === NULL) { return 0; } else { return 1; } } } function teste($var) { $result = CountHelper::count_if_you_can($var); var_dump($result); $result = count($var); var_dump($result); if ($var >= 1){ foreach ($var as $v) { echo $v; } } } echo teste(123);
based on gpCh9
Output for 7.2.0 - 7.3.0rc3
int(1) Warning: count(): Parameter must be an array or an object that implements Countable in /in/Qqh2T on line 38 int(1) Warning: Invalid argument supplied for foreach() in /in/Qqh2T on line 42
Output for 5.6.38 - 7.1.23
int(1) int(1) Warning: Invalid argument supplied for foreach() in /in/Qqh2T on line 42