pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by Ex on Sun 5th Sep 18:35
download | new post

  1. <?php
  2.   /**
  3.    * @desc   works out the variables in the current scope(from where function was called).
  4.    *         Returns an array with variable name as key and vaiable value as value
  5.    * @param  $varList: variables returned by get_defined_vars() in desired scope.
  6.    *         $excludeList: variables to be excluded from the list.
  7.    * @return array
  8.    */
  9.   function getDefinedVars($varList, $excludeList)
  10.   {
  11.       $temp1 = array_values(array_diff(array_keys($varList), $excludeList));
  12.       $temp2 = array();
  13.       while (list($key, $value) = each($temp1)) {
  14.           global $$value;
  15.           $temp2[$value] = $$value;
  16.       }
  17.       return $temp2;
  18.   }
  19.  
  20.   /**
  21.    * @desc   holds the variable that are to be excluded from the list.
  22.    *         Add or drop new elements as per your preference.
  23.    * @var    array
  24.    */
  25.   $excludeList = array('GLOBALS', '_FILES', '_COOKIE', '_POST', '_GET', 'excludeList');
  26.  
  27.   //some dummy variables; add your own or include a file.
  28.   $firstName = 'kailash';
  29.   $lastName = 'Badu';
  30.   $test = array('Pratistha', 'sanu', 'fuchhi');
  31.  
  32.   //get all variables defined in current scope
  33.   $varList = get_defined_vars();
  34.  
  35.   //Time to call the function
  36.   print "<pre>";
  37.   print_r(getDefinedVars($varList, $excludeList));
  38.   print "</pre>";
  39. ?>

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings