Miscellaneous Code

  Home arrow Miscellaneous Code arrow Simple Debug functions
MISCELLANEOUS CODE

Simple Debug functions
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-07-26

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    A few debug functions based on a function I got off php.net (original function is included - it is from user notes on php.net)

    By : Taoism

    <?php
    /**
    * a variable to control whether debug code is displayed or not
    *
    * @param boolean $debug boolean to toggle debug code showing or not showing
    *
    */
    $debug=true;
    //$debug=false;

    /**
    * simple debug function
    *
    * got this function from the user-feedback section for the
    * print_r php function on www.php.net
    * its very useful for debugging
    *
    * @param mixed $call a variable to be dumped for display
    * @param string $cname a string to describe variable being dumped
    *
    *
    */
    function dp($call,$cname) {
    global $debug;
    if($debug){
    echo "<br/>".$cname.":<pre>";
    if(!is_array($call)){$call=htmlspecialchars($call);}
    print_r($call);
    if(is_array($call)){reset($call);}
    echo "</pre><hr/>\n";
    }//end function dp() ======================
    }//end dp

    /**
    * a function to display multiple variables side-by-side
    *
    * an extended version of dp()
    * it takes an array in and dynamically creates variable names
    * based on the array passed in so that side-by-side
    * comparissons of variables can be done.
    * this is most useful for comparing scopes...
    * i.e. the $_POST scope to the $_SESSION scope...
    * example of a call:
    * dpa(array('xvar'=>'$xvar','AUTH'=>'$AUTH','tmp_AUTH_admin'=>'$tmp_AUTH_admin','x'=>'array_intersect($AUTH["xvar"],$xvar)'));
    * Note that the key=>val pairs are VARNAME=>LABLE_TO_DESCRIBE.
    * The varname has no $ so that it can be dynamically called within the function
    *
    * @author Keith Young
    * @version 1.0
    * @param array $dbug an array of key=>var pairs where the key is a variable name with no $, and the var is a lable to describe the key
    * @global boolean $debug used to check if the function should run or not
    * @global mixed $key this is a mixed data type based on the key value of the array passed in.
    *
    * @see dp()
    *
    */
    function dpa($dbug) {
    global $debug;
    echo '<br/>';
    foreach($dbug as $key=>$val){global ${$key};}
    if($debug){
    $rspan=count($dbug);
    ($rspan==0)?$colpct=100:$colpct=100/$rspan;
    echo '<table cellspacing="2" cellpadding="5" width="75%" style="background-color:black;">'."\n";
    echo '<tr><th colspan="'.$rspan.'" style="background-color:lightgrey;font-size:11pt; font-family:"Verdana";font-weight:bold;color:black;"> D E B U G : </th></tr>'."\n";
    echo '<tr>'."\n";

    foreach($dbug as $key=>$val){
    echo '<td width="'.$colpct.'%" valign="top" style="background-color:white;font-size:8pt; font-family:"Verdana";font-weight:normal;color:black;">'."\n";
    echo '<span style="background-color:white;font-size:10pt; font-family:"Verdana";font-weight:bold;color:blue;">"'.$val.'":</span> <pre>'."\n";
    if(!is_array(${$key})){${$key}=htmlspecialchars(${$key});}
    print_r(${$key});
    if(is_array(${$key})){reset(${$key});}
    echo '</pre>'."\n";
    echo '</td>'."\n";
    }
    echo '</tr></table><hr width="75%" align="left">'."\n";
    }
    }//end function dpa()

    /**
    * a function to display multiple variables side-by-side with the datatype of each variable displayed as well
    *
    * an extended version of dp()
    * it takes an array in and dynamically creates variable names based on the array passed in so that side-by-side
    * comparissons of variables can be done.
    * this is most useful for comparing scopes...
    * i.e. the $_POST scope to the $_SESSION scope...
    * This function also displays the datatype of each variable
    * example of a call:
    * dpa(array('xvar'=>'$xvar','AUTH'=>'$AUTH','tmp_AUTH_admin'=>'$tmp_AUTH_admin','x'=>'array_intersect($AUTH["xvar"],$xvar)'));
    * Note that the key=>val pairs are VARNAME=>LABLE_TO_DESCRIBE.
    * The varname has no $ so that it can be dynamically called within the function
    *
    * @author Keith Young
    * @version 1.0
    * @param array $dbug an array of key=>var pairs where the key is a variable name with no $, and the var is a lable to describe the key
    * @global boolean $debug used to check if the function should run or not
    * @global mixed $key this is a mixed data type based on the key value of the array passed in.
    *
    * @see dp()
    *
    */
    function vdpa($dbug) {
    global $debug;
    echo '<br/>';
    foreach($dbug as $key=>$val){global ${$key};}
    if($debug){
    $rspan=count($dbug);
    ($rspan==0)?$colpct=100:$colpct=100/$rspan;
    echo '<table cellspacing="2" cellpadding="5" width="75%" style="background-color:black;">'."\n";
    echo '<tr><th colspan="'.$rspan.'" style="background-color:lightgrey;font-size:11pt; font-family:"Verdana";font-weight:bold;color:black;"> D E B U G : </th></tr>'."\n";
    echo '<tr>'."\n";

    foreach($dbug as $key=>$val){
    echo '<td width="'.$colpct.'%" valign="top" style="background-color:white;font-size:8pt; font-family:"Verdana";font-weight:normal;color:black;">'."\n";
    echo '<span style="background-color:white;font-size:10pt; font-family:"Verdana";font-weight:bold;color:blue;">"'.$val.'":</span> <pre>'."\n";
    if(!is_array(${$key})){${$key}=htmlspecialchars(${$key});}
    var_dump(${$key});
    if(is_array(${$key})){reset(${$key});}
    echo '</pre>'."\n";
    echo '</td>'."\n";
    }
    echo '</tr></table><hr width="75%" align="left">'."\n";
    }
    }//end function vdpa()
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap