3v4l.org

run code in 300+ PHP versions simultaneously
<?php set_error_handler( function($error_num, $message, $file_name, $line_num) { $trace = debug_backtrace(); foreach($trace as $trace_row){ array_walk_recursive($trace, function(&$val, $index){ $max_length = 100; //The strlen(...) function has to be passed a string value, so convert objects to their respective class names - otherwise an error will be thrown if ( is_object($val) ) { $val = get_class($val); } $length = strlen($val); if( $length > $max_length ){ $val = substr($val, 0, $max_length) . "...(original length $length)"; } }); } return true; } ); class A{ function do_stuff(&$b) { var_dump('Before in function:', $b); $defined = 0; #trigger_error("If I fixed the undefined variable but enabled this line instead, it will also turn b from an object into a string! So user-triggered notices bork it as well."); $x = $undefined || $defined ? 14 : 0; var_dump('After in function:', $b); } } class B{} $a = new A(); $b = new B(); $a->do_stuff($b); var_dump('After function:', $b); ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
string(19) "Before in function:" object(B)#3 (0) { } string(18) "After in function:" object(B)#3 (0) { } string(15) "After function:" object(B)#3 (0) { }
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33
string(19) "Before in function:" object(B)#3 (0) { } string(18) "After in function:" string(1) "B" string(15) "After function:" string(1) "B"
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/FUqWS on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/FUqWS on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/FUqWS on line 3
Process exited with code 255.

preferences:
255.95 ms | 401 KiB | 356 Q