note 100195 deleted from language.variables by googleguy

From: Date: Sat, 12 Jan 2013 11:00:05 +0000
Subject: note 100195 deleted from language.variables by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192978@lists.php.net to get a copy of this message
Note Submitter: james at custom-made-sites dot com ---- This script has been running around for a while and has add many additions and changes, however I noticed that if you run it and there is an object assigned to a variable it will fail with 'Object of Class 'XXXX' cannot be converted to string' so I changed it a little to ignore objects within the script and display the variables only: Btw, it has haelped me an ENOURMOUS amount over the years especially when keeping track of variables that are being sent through request and if session variables are alive <?php //this can be removed if you want to find out if you page has actually started a session, - this is sometimes a problem when relying on a session being started by an included/required file if(!isset($_SESSION)) { session_start(); } //now begin the table echo '<table border=1><tr> <th>variable</th> <th>value</th> </tr>'; foreach(get_defined_vars() as $key => $value) { //if the returned value is NOT an object... if (is_array ($value) && !is_object($key) && !is_object($value)) { echo '<tr><td>$'.$key .'</td><td>'; if ( sizeof($value)>0 ) { echo '"<table border=1><tr> <th>key</th> <th>value</th> </tr>'; foreach ($value as $skey => $svalue ) { //and if these values are NOT an object... if ( !is_object($skey) && !is_object($svalue)) { echo '<tr><td>[' . $skey .']</td><td>"'. $svalue .'"</td></tr>'; } } echo '</table>"'; } else { echo 'EMPTY'; } echo '</td></tr>'; }else { echo '<tr><td>[' . $key .']</td><td>"'. $value .'"</td></tr>'; } } echo '</table>'; ?>

« previous php.notes (#192978) next »