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)); }
Output for 8.3.0 - 8.3.14
------------ true !empty() = bool(true) count() = Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, true given in /in/1mkY5:14 Stack trace: #0 {main} thrown in /in/1mkY5 on line 14
Process exited with code 255.
Output for 8.0.10 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25
------------ true !empty() = bool(true) count() = Fatal error: Uncaught TypeError: count(): Argument #1 ($value) 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 8.0.0 - 8.0.9
------------ 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.33, 7.4.0 - 7.4.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) ------------ (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)

preferences:
98.64 ms | 417 KiB | 5 Q