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 = sizeof($var); var_dump($result); if (count($var) > 0){ foreach ($var as $v) { echo $v; } } } echo teste('');
based on Ws9Uv
Output for 7.2.0 - 7.3.0rc3
int(1) Warning: sizeof(): Parameter must be an array or an object that implements Countable in /in/BEbSE on line 40 int(1) Warning: count(): Parameter must be an array or an object that implements Countable in /in/BEbSE on line 43 Warning: Invalid argument supplied for foreach() in /in/BEbSE on line 44
Output for 5.6.38 - 7.1.23
int(1) int(1) Warning: Invalid argument supplied for foreach() in /in/BEbSE on line 44