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
developerWorks - FREE Tools! |
As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
|
|
|
|
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!
|
|
|
|
Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications. FREE! Go There Now!
|
|
|
|
IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects. FREE! Go There Now!
|
|
|
|
Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic. FREE! Go There Now!
|
|
|
|
Whether you are creating new applications or modifying existing ones, managing integration of new components with traditional z/OS elements is a critical part of building and deploying modern applications. Listen to this webcast to see how IBM can help you optimize your development process using an IDE like Rational Developer for System z that integrates with management tools, such as ClearCase to manage your application development on mainframes. FREE! Go There Now!
|
|
|
|
Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |