<?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);
?>