Debugging PHP scripts

Debugging PHP scripts

It will display all GET and POST variables and all the properties on a currently defined object.The code

(copy this in debug.php)

function DebugClass($class)
{
$class_vars = get_object_vars($class);
echo "<b>
<u>Class contents</b></u><br<br>";
foreach ($class_vars as $key => $value)
echo "
<b>Property Name: </b>".$key." <b>Property Value: </b>".$value."<br>";
}
//this displays all get and post variables
function DebugIncoming()
{
echo "
<b><u>GET and POST contents</b></u><br><br>";
echo "
<b><font color=\"red\">GET contents</b></font><br><br>";
foreach ($_GET as $key=> $value)
echo "
<b>Variable Name: </b>".$key." <b>>Variable Value: </b>".$value."<br>";

echo “<br><br>";

echo “<b><font color=\"red\">POST contents</b></font><br><br>";
foreach ($_POST as $key=> $value)
echo "
<b>Variable Name: </b>".$key." <b>Variable Value: </b>".$value."<br>";
echo "
<br><br>";
}
//display all current POST and GET values
DebugIncoming();

Usage

Include the above file from a script you would like to debug. Also, to print out all of the currently defined properties of a class instance, use the following function:

DebugClass($objectInstance);

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.