<?php
function dump( $var ) {
$result = var_export( $var, true );
$loc = whereCalled();
return "\n<pre>Dump: $loc\n$result</pre>";
}
function whereCalled( $level = 1 ) {
$trace = debug_backtrace();
$file = $trace[$level]['file'];
$line = $trace[$level]['line'];
$object = $trace[$level]['object'];
if (is_object($object)) { $object = get_class($object); }
return "Where called: line $line of $object \n(in $file)";
}
?>
In addition, calling 'whereCalled()' from any function will quickly identify locations that are doing something unexpected (e.g., updating a property at the wrong time). I'm new to PHP, but have used the equivalent in Perl for years.
----
Server IP: 69.147.83.197
Probable Submitter: 201.206.250.26
----
Manual Page -- http://www.php.net/manual/en/function.debug-backtrace.php
Edit -- https://master.php.net/note/edit/99752
Del: integrated -- https://master.php.net/note/delete/99752/integrated
Del: useless -- https://master.php.net/note/delete/99752/useless
Del: bad code -- https://master.php.net/note/delete/99752/bad+code
Del: spam -- https://master.php.net/note/delete/99752/spam
Del: non-english -- https://master.php.net/note/delete/99752/non-english
Del: in docs -- https://master.php.net/note/delete/99752/in+docs
Del: other reasons-- https://master.php.net/note/delete/99752
Reject -- https://master.php.net/note/reject/99752
Search -- https://master.php.net/manage/user-notes.php