3v4l.org

run code in 300+ PHP versions simultaneously
<?php $vars = array( true, false, null, 'string', array(), array(1),array(1, 2, 3), new stdClass() ); foreach ($vars as $var) { echo "------------\r"; var_export($var); echo "\r"; echo "!empty() = "; var_dump(!empty($var)); echo "count() = "; var_dump(count($var)); }
based on Q6Rag
Output for 8.0.0
------------ true !empty() = bool(true) count() = Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, bool given in /in/1mkY5:14 Stack trace: #0 {main} thrown in /in/1mkY5 on line 14
Process exited with code 255.
Output for 7.3.0 - 7.3.26, 7.4.0 - 7.4.14
------------ true !empty() = bool(true) count() = Warning: count(): Parameter must be an array or an object that implements Countable in /in/1mkY5 on line 14 int(1) ------------ false !empty() = bool(false) count() = Warning: count(): Parameter must be an array or an object that implements Countable in /in/1mkY5 on line 14 int(1) ------------ NULL !empty() = bool(false) count() = Warning: count(): Parameter must be an array or an object that implements Countable in /in/1mkY5 on line 14 int(0) ------------ 'string' !empty() = bool(true) count() = Warning: count(): Parameter must be an array or an object that implements Countable in /in/1mkY5 on line 14 int(1) ------------ array ( ) !empty() = bool(false) count() = int(0) ------------ array ( 0 => 1, ) !empty() = bool(true) count() = int(1) ------------ array ( 0 => 1, 1 => 2, 2 => 3, ) !empty() = bool(true) count() = int(3) ------------ (object) array( ) !empty() = bool(true) count() = Warning: count(): Parameter must be an array or an object that implements Countable in /in/1mkY5 on line 14 int(1)
Output for 7.2.0 - 7.2.33
------------ true !empty() = bool(true) count() = Warning: count(): Parameter must be an array or an object that implements Countable in /in/1mkY5 on line 14 int(1) ------------ false !empty() = bool(false) count() = Warning: count(): Parameter must be an array or an object that implements Countable in /in/1mkY5 on line 14 int(1) ------------ NULL !empty() = bool(false) count() = Warning: count(): Parameter must be an array or an object that implements Countable in /in/1mkY5 on line 14 int(0) ------------ 'string' !empty() = bool(true) count() = Warning: count(): Parameter must be an array or an object that implements Countable in /in/1mkY5 on line 14 int(1) ------------ array ( ) !empty() = bool(false) count() = int(0) ------------ array ( 0 => 1, ) !empty() = bool(true) count() = int(1) ------------ array ( 0 => 1, 1 => 2, 2 => 3, ) !empty() = bool(true) count() = int(3) ------------ stdClass::__set_state(array( )) !empty() = bool(true) count() = Warning: count(): Parameter must be an array or an object that implements Countable in /in/1mkY5 on line 14 int(1)
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25
------------ true !empty() = bool(true) count() = int(1) ------------ false !empty() = bool(false) count() = int(1) ------------ NULL !empty() = bool(false) count() = int(0) ------------ 'string' !empty() = bool(true) count() = int(1) ------------ array ( ) !empty() = bool(false) count() = int(0) ------------ array ( 0 => 1, ) !empty() = bool(true) count() = int(1) ------------ array ( 0 => 1, 1 => 2, 2 => 3, ) !empty() = bool(true) count() = int(3) ------------ stdClass::__set_state(array( )) !empty() = bool(true) count() = int(1)