3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $values = [ #ints 0,1,2,-1,-2, #floats 0.0,0.1,0.2,1.0,1.1,2.0,2.1, -0.1,-0.2,-1.0,-1.1,-2.0,-2.1, #strings "", "a", "0","@","NULL", #bool true, false, #array [], ["a"],[[]], #object new stdClass, #null NULL,"\0", function(){}, ]; foreach($values as $k => $v){ if(is_scalar($v)){ $j = new stdClass; $j->p = $v; $test[] = $j; } } foreach($values as $k => $v){ echo (string) $v ?: "fail", "\n"; }
based on 3Q9LK
Output for 7.1.0 - 7.2.0
fail 1 2 -1 -2 fail 0.1 0.2 1 1.1 2 2.1 -0.1 -0.2 -1 -1.1 -2 -2.1 fail a fail @ NULL 1 fail Notice: Array to string conversion in /in/CBQ04 on line 31 Array Notice: Array to string conversion in /in/CBQ04 on line 31 Array Notice: Array to string conversion in /in/CBQ04 on line 31 Array Recoverable fatal error: Object of class stdClass could not be converted to string in /in/CBQ04 on line 31
Process exited with code 255.
Output for 5.4.10 - 7.0.20
fail 1 2 -1 -2 fail 0.1 0.2 1 1.1 2 2.1 -0.1 -0.2 -1 -1.1 -2 -2.1 fail a fail @ NULL 1 fail Notice: Array to string conversion in /in/CBQ04 on line 31 Array Notice: Array to string conversion in /in/CBQ04 on line 31 Array Notice: Array to string conversion in /in/CBQ04 on line 31 Array Catchable fatal error: Object of class stdClass could not be converted to string in /in/CBQ04 on line 31
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/CBQ04 on line 3
Process exited with code 255.