note 85249 added to function.get-defined-vars

From: Date: Thu, 21 Aug 2008 22:52:03 +0000
Subject: note 85249 added to function.get-defined-vars
Groups: php.notes 
Request: Send a blank email to php-notes+get-143725@lists.php.net to get a copy of this message
Here's a very simple function for debugging. It's far from perfect but I find it very handy. It outputs the var value and the var name on a new line. The problem is it'll echo any vars and their name if they share the same value. No big deal when debugging and saves the hassle of writing the HTML and var name when echoing a variable. (ev=echo variable). Using get_defined_vars() inside a function renames the var name to the functions variable so isn't as useful for debugging. Of course, you'll need access to the $GLOBALS array <? function ev($variable){ foreach($GLOBALS as $key => $value){ if($variable===$value){ echo '<p>'.$key.' - '.$value.'</p>'; } } } $a=0; ev($a); $b=0; ev($b); $c=0; ev($c); ?> Will output a - 0 a - 0 b - 0 a - 0 b - 0 c - 0 ---- Server IP: 209.41.74.194 Probable Submitter: 209.194.189.187 ---- Manual Page -- http://www.php.net/manual/en/function.get-defined-vars.php Edit -- https://master.php.net/note/edit/85249 Del: integrated -- https://master.php.net/note/delete/85249/integrated Del: useless -- https://master.php.net/note/delete/85249/useless Del: bad code -- https://master.php.net/note/delete/85249/bad+code Del: spam -- https://master.php.net/note/delete/85249/spam Del: non-english -- https://master.php.net/note/delete/85249/non-english Del: in docs -- https://master.php.net/note/delete/85249/in+docs Del: other reasons-- https://master.php.net/note/delete/85249 Reject -- https://master.php.net/note/reject/85249 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143725) next »