Voting

: seven plus one?
(Example: nine)

The Note You're Voting On

michael dot schramm at gmail dot com
15 years ago
Be carefull if you are using objects as arguments for function calls!

<?php
error_reporting
(E_ALL);

function
myPrint($trace){
foreach(
$trace as $i=>$call){
/**
* THIS IS NEEDED! If all your objects have a __toString function it's not needed!
*
* Catchable fatal error: Object of class B could not be converted to string
* Catchable fatal error: Object of class A could not be converted to string
* Catchable fatal error: Object of class B could not be converted to string
*/
if (is_object($call['object'])) { $call['object'] = 'CONVERTED OBJECT OF CLASS '.get_class($call['object']); }
if (
is_array($call['args'])) {
foreach (
$call['args'] AS &$arg) {
if (
is_object($arg)) { $arg = 'CONVERTED OBJECT OF CLASS '.get_class($arg); }
}
}

$trace_text[$i] = "#".$i." ".$call['file'].'('.$call['line'].') ';
$trace_text[$i].= (!empty($call['object'])?$call['object'].$call['type']:'');
$trace_text[$i].= $call['function'].'('.implode(', ',$call['args']).')';
}

var_dump($trace_text);
}

class
A{
public function
test($obj){
$obj->test();
}
}

class
B{
public function
test(){
echo
myPrint(debug_backtrace());
}
}

$A = new A();
$B = new B();

$A->test($B);

?>

<< Back to user notes page

To Top