Miscellaneous Code
  Home arrow Miscellaneous Code arrow Simple Debug functions
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
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:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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

     

    IBM® developerWorks developerWorks - FREE Tools!


    Check out the new Jazz space on developerWorks

    <a href="http://zeus.developershed.com/shonuff.php?blackbird=3853&zoneid=442&source=&dest=http%3A%2F%2Fwww.ibm.com%2Fdeveloperworks%2Fspaces%2Fjazz%3FS_TACT%3D105AGY31%26S_CMP%3DDEVSHED&ismap="><img src="http://images.devshed.com/corp/img/news/jazz01.gif" alt="developerWorks Jazz space" align="left"></a>You've heard the buzz about Jazz... want to know more about it from a developer's perspective? Check out the Jazz space on developerWorks. This space is an up-to-date resource for developers, including technical information about Jazz and products built on Jazz, like Rational Team Concert Express. The Jazz space includes content from a wide variety of sources, including links, feeds, and comments from experts.
    FREE! Go There Now!


    NEW! Accelerating Software Innovation on i on Power Systems

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, for an overview of Rational’s new software offerings and resources to help modernize and accelerate software innovation on i on Power Systems – while ensuring past application investments are protected and continue to grow. Learn how these solutions are helping customers extend their core i5/OS solutions toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Addressing software-as-a-service challenges using Tivoli security and WebSphere solutions

    Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base.
    FREE! Go There Now!


    NEW! Applying lean thinking to the governance of software development

    Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations.
    FREE! Go There Now!


    NEW! BlammoSplat: Build a community Web site of OpenLaszlo animations, Part 3: The community animation

    Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo.
    FREE! Go There Now!


    NEW! Discovering the value of WebSphere Process Server

    WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Developer for System i V7.1

    Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications.
    FREE! Go There Now!


    NEW! IBM Rational ClearCase Innovator's Series

    Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Process

    Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly.
    FREE! Go There Now!


    Refresh! IBM Rational Systems Development Solution eKit

    With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds
    - [PHP5] NOTIMEOUT PACKAGE
    - Class to return variables to a Flash movie.
    - BCGCD Greatest Common Denominator (Large Num...
    - HMAC
    - Binary to Decimal
    - Decimal to Binary using logs
    - web.framework v1.0.0
    - Shopping Cart Class






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway