Xdebug (http://xdebug.org) is probably one of the best ways to debug PHP code. But Xdebug can be difficult to setup, depending on the environment.
Here's a quick and dirty method to see a select list of PHP variables. This was lifted from the notes at http://php.net/manual/en/function.get-defined-vars.php.
function getDefinedVars($varList, $excludeList) {
$temp1 = array_values(array_diff(array_keys($varList), $excludeList));
$temp2 = array();
while (list($key, $value) = each($temp1)) {
global $$value;
$temp2[$value] = $$value;
}
return $temp2;
}
$excludeList = array('GLOBALS', '_FILES', '_COOKIE', '_POST', '_GET',
'HTTP_COOKIE_VARS', 'HTTP_SERVER_VARS', '_SERVER', 'HTTP_ENV_VARS',
'_ENV', 'HTTP_POST_FILES', 'HTTP_SESSION_VARS', 'excludeList');
print_r(getDefinedVars(get_defined_vars(), $excludeList));