3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test($array) { try { $array = (object)$array; return is_indexed_array($array); } catch (Exception $e) { echo $e->getMessage(); return 'error'; } } assert(test([]) === true); assert(test(['', 'a', 'b']) === true); // proper indexed array; also, to catch wrong isset usage assert(test([1 => 'a', 2 => 'b', 3 => 'c']) === false); // sequential but not 0-based assert(test([-1 => '', 0 => '', 1 => 'a']) === false); // sequential but not 0-based assert(test([0 => '', 2 => 'b', 3 => 'c']) === false); // 1 index missing assert(test([0 => '', 2 => 'b', 1 => 'a']) === false); // numeric but unordered assert(test([0 => '']) === true); // single item assert(test([1 => 'a']) === false); // single item assert(test([NAN]) === true); assert(test([NAN => '']) === false); assert(test([INF]) === true); assert(test([INF => '']) === false); assert(test([' ' => '', 'a' => 'a', 'b' => 'b']) === false); // proper associative array assert(test([' ' => '']) === false); // single item; also, associative even though '' == 0 assert(test([' ' => '', 1 => 'a']) === false); // first key string but rest not assert(test([' ' => '', 0 => '']) === false); // first key string but rest not assert(test([0 => '', 'a' => 'a']) === false); // first key numeric but rest not assert(test([' 0' => '']) === false); // associative even though ' 0' == 0 assert(test(['00' => '']) === false); // associative even though '00' == 0 assert(test(['0*' => '']) === false); // associative even though '0*' == 0 assert(test(['0.0' => '']) === false); // associative even though '0.0' == 0.0 assert(test(['0x0' => '']) === false); // associative even though '0x0' == 0 assert(test(['0e0' => '']) === false); // associative even though '0e0' == 0 assert(test(['-0' => '']) === false); // associative even though '0e0' == 0 $obj = new stdClass; $obj->{0} = ''; assert(test((array)$obj) === false); // to catch ['0' => ''] like situations function is_indexed_array($array) { foreach (array_keys($array) as $k => $v) if ($k !== $v) return false; return true; }
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: array_keys(): Argument #1 ($array) must be of type array, stdClass given in /in/f7Ma0:49 Stack trace: #0 /in/f7Ma0(49): array_keys(Object(stdClass)) #1 /in/f7Ma0(8): is_indexed_array(Object(stdClass)) #2 /in/f7Ma0(19): test(Object(stdClass)) #3 {main} thrown in /in/f7Ma0 on line 49
Process exited with code 255.

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:
47.03 ms | 401 KiB | 8 Q