Code: Select all
<?php
class Profile
{
static $alt;
static $depth;
/**
* Echo out a profile of the variable in a nice table
*
* @param string $var the variable to analyze
* @param string $note an optional caption for the table
* @return void
*/
static function info( $var, $note=null )
{
self::$depth = 1;
echo '<br /><br />' . self::getInfoTable( $var, $note );
}
/**
* Profile off current $_POST data
*
* @return void
*/
static function post()
{
if( isset($_POST) ) self::info($_POST, '$_POST Data');
else echo '$_POST is not set';
}
/**
* Profile off current $_GET data
*
* @return void
*/
static function get()
{
if( isset($_GET) ) self::info($_GET, '$_GET Data');
else echo '$_GET is not set';
}
/**
* Profile off current $_SESSION data
*
* @return void
*/
static function session()
{
if( isset($_SESSION) ) self::info($_SESSION, '$_SESSION Data');
else echo '$_SESSION is not set';
}
/**
* Profile off current $_SERVER data
*
* @return void
*/
static function server()
{
if( isset($_SERVER) ) self::info($_SERVER, '$_SERVER Data');
else echo '$_SERVER is not set';
}
/**
* Profile off current $_POST, $_GET, $_SESSION, & $_SERVER data
*
* @return void
*/
static function all()
{
self::session();
self::post();
self::get();
self::server();
}
/**
* make a table with information about the current variable, if the variable contains an object / array
* run that object / array through this function recursively to make another table (max depth = 25)
*
* @param string $var
* @param string $note
* @return void
* @author TMI
*/
static function getInfoTable( $var, $note = null )
{
self::$depth = self::$depth + 1;
if( self::$depth > 25 ) {
echo 'Recursive analysis existed to prevent possible endless loop';
return '';
}
if( is_object($var) ) $varclass = get_class($var);
$var = (array) $var;
$html =
'
<table style="border: solid 1px black;">
<caption style="text-align: center; font-weight: bold">' . $note . ' (<u style="text-decoration: underline;">' . $varclass . '</u> '. gettype($var) . ')</caption>
<tr style="font-weight: bold;">
<th style="background: #D8D8D8; padding: 2px">Key</th>
<th style="background: #D8D8D8; padding: 2px">Type</th>
<th style="background: #D8D8D8; padding: 2px">Value</th>
</tr>';
foreach( $var as $key => $value )
{
if( self::$alt == "#EDEDED" ) self::$alt = "#FFF";
else self::$alt = "#EDEDED";
if( is_array($value) || is_object($value) )
$listedValue = Profile::getInfoTable($value);
else
$listedValue = htmlentities($value);
$html.='
<tr>
<td style="background: #A0A0A0; text-align: right; padding: 3px; color: white">' . $key . '</td>
<td style="background: ' . self::$alt . '; padding: 3px; font-style: italic; ">' . ' ' . gettype($value) . '</td>
<td style="background: ' . self::$alt . '; padding: 3px;">' . $listedValue . '</td>
</tr>';
}
$html .= '</table>';
return $html;
}
}Code: Select all
<?php
// to examine an array or an object
Profile::info( $myVar );
// equivalent to writing Profile::info( $_POST );
Profile::post();
// equivalent to writing Profile::info( $_SESSION );
Profile::session();
// etc...