3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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); ?>
based on fZij6
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
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 hhvm-3.10.0 - 3.13.2
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 4.4.2 - 4.4.9, 5.1.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.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.