3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CountMe implements Countable { private $_count; public function __construct($fixedCount) { $this->_count = $fixedCount; } public function count() { return $this->_count; } } $fourtytwo = new CountMe(42); $zero = new CountMe(0); var_dump( count($fourtytwo), count($fourtytwo)==0, empty($fourtytwo), $fourtytwo == array(), $fourtytwo === array() ); print str_repeat('-', 42)."\n"; var_dump( count($zero), count($zero)==0, empty($zero), $zero == array(), $zero === array() );
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Deprecated: Return type of CountMe::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/JqcaY on line 12 int(42) bool(false) bool(false) bool(false) bool(false) ------------------------------------------ int(0) bool(true) bool(false) bool(false) bool(false)
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
int(42) bool(false) bool(false) bool(false) bool(false) ------------------------------------------ int(0) bool(true) bool(false) bool(false) bool(false)

preferences:
115.87 ms | 409 KiB | 5 Q