3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $a; protected $b; public $c; } class FooCountable implements \Countable { private $elements = [1,2,3]; public function count() { return count($this->elements); } } $tests = [ 'array' => [1,2,3], 'string' => 'hello world', 'number' => 123, 'iterator' => new \ArrayIterator([1,2,3]), 'countable' => new \FooCountable(), 'zero' => 0, 'string_zero' => '0', 'object' => new \Foo(), 'stdClass' => new \stdClass, 'null' => null, 'empty' => '', 'boolt' => true, 'boolf' => false ]; function countValid($array_or_countable, $mode = \COUNT_NORMAL) { if ( (\PHP_VERSION_ID >= 70300 && \is_countable($array_or_countable)) || \is_array($array_or_countable) || $array_or_countable instanceof \Countable ) { return \count($array_or_countable, $mode); } return null === $array_or_countable ? 0 : 1; } foreach($tests as $key => $test) { echo $key . ': ' . print_r(countValid($test), 1) . \PHP_EOL; } echo 'undefined: ' . print_r(countValid($undefined), 1) . \PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of FooCountable::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/8M0Wd on line 14 array: 3 string: 1 number: 1 iterator: 3 countable: 3 zero: 1 string_zero: 1 object: 1 stdClass: 1 null: 0 empty: 1 boolt: 1 boolf: 1 Warning: Undefined variable $undefined in /in/8M0Wd on line 53 undefined: 0

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
62.87 ms | 402 KiB | 8 Q