note 100195 added to language.variables

From: Date: Thu, 30 Sep 2010 11:55:44 +0000
Subject: note 100195 added to language.variables
Groups: php.notes 
Request: Send a blank email to php-notes+get-172838@lists.php.net to get a copy of this message
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>'; ?> ---- Server IP: 69.147.83.197 Probable Submitter: 90.206.175.169 ---- Manual Page -- http://www.php.net/manual/en/language.variables.php Edit -- https://master.php.net/note/edit/100195 Del: integrated -- https://master.php.net/note/delete/100195/integrated Del: useless -- https://master.php.net/note/delete/100195/useless Del: bad code -- https://master.php.net/note/delete/100195/bad+code Del: spam -- https://master.php.net/note/delete/100195/spam Del: non-english -- https://master.php.net/note/delete/100195/non-english Del: in docs -- https://master.php.net/note/delete/100195/in+docs Del: other reasons-- https://master.php.net/note/delete/100195 Reject -- https://master.php.net/note/reject/100195 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172838) next »