note 94156 added to function.debug-backtrace
| From: | michael dot schramm at gmail dot com | Date: | Tue, 20 Oct 2009 07:29:02 +0000 |
| Subject: | note 94156 added to function.debug-backtrace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161893@lists.php.net to get a copy of this message | ||
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);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 83.64.229.226
----
Manual Page -- http://www.php.net/manual/en/function.debug-backtrace.php
Edit -- https://master.php.net/note/edit/94156
Del: integrated -- https://master.php.net/note/delete/94156/integrated
Del: useless -- https://master.php.net/note/delete/94156/useless
Del: bad code -- https://master.php.net/note/delete/94156/bad+code
Del: spam -- https://master.php.net/note/delete/94156/spam
Del: non-english -- https://master.php.net/note/delete/94156/non-english
Del: in docs -- https://master.php.net/note/delete/94156/in+docs
Del: other reasons-- https://master.php.net/note/delete/94156
Reject -- https://master.php.net/note/reject/94156
Search -- https://master.php.net/manage/user-notes.php