SITERAW

Access variables outside of a PHP function

Author Message
Locust # Posted yesterday
Locust

Hello

I'm trying to code a PHP error display function

function onError($errno, $errstr, $errfile, $errline)
{
echo '<strong>Error : '.$errstr.'<br/>';
echo '<strong>File :</b>'.$errfile.' '.$errline.'<br/>';
echo '<strong>Variables : </strong>';
dump_debug (get_defined_vars());
echo '<br/><strong>Included files : </strong>';
dump_debug (get_included_files());
return true;
}

set_error_handler ("onError", E_ALL);
except that the dump only show me the variables present in the function, whereas I want all the variables of the code if possible

Do you know how to do it ?

thank you !

Ads
Phoenix # Posted yesterday
Phoenix

Your code is disgusting, and I say that as someone who has forked both your sisters.

Otherwise -> global variables.

Valter # Posted two hours ago
Valter

Either you somehow manage to ensure that the variables are passed as arguments in your function.

Either, as the transsexual above suggests, you use $GLOBALS.

Locust # Posted two hours ago
Locust

Ok, I have my variables with GLOBALS thank you.

the problem is that GLOBALS seems to bite its tail and tends to include itself in its variables which causes an infinite iteration of the dump function...

do you have an idea of how to get out of this predicament, without resorting to the brutish method which would "block" the loop after a predetermined number of laps?

Phoenix # Posted one hour ago
Phoenix

unset($GLOBALS['GLOBALS']);
Or some equivalent noobistry.

Valter # Posted one hour ago
Valter

if ($key != 'GLOBALS')
rather.

In or before the dump function preferably.

@Phoenix: You who likes to bitch about disgusting code.

Locust # Posted 7 minutes ago
Locust

thank you !

it works flawlessly, that's exactly what I wanted!

Post a reply

Please be kind and courteous in your replies. Don't roast others for no reason.