Welcome Guest, Not a member yet? Register   Sign In
dev_helper
#1

[eluser]TheFuzzy0ne[/eluser]
Hi everyone.

Debugging an app can be a real pain. When you're had to type:

Code:
die('<pre>'.print_r($arr, TRUE).'</pre>');

for the millionth time, it starts growing tiresome. As you know, this is an ideal situation where helpers can make things easier.

I'm sure there are other's out there who use helpers to ease development, and I'd like to encourage everyone to contribute to this thread with any suggestions for a new helper.

At the moment, I only have two functions in my helper:

Code:
&lt;?php

function pprint_r($arr, $echo=TRUE)
{
    $output = '<pre>';
    $output .= htmlspecialchars(print_r($arr, TRUE));
    $output .= '</pre>';
    
    if ($echo === TRUE)
    {
        echo $output;
        
        return TRUE;
    }
    
    return $output;
}

function dprint_r($arr)
{
    die(pprint_r($arr, FALSE));
}

It's quite simple really. pprint_r() is the equivalent of:
Code:
'<pre>'.print_r($arr, TRUE).'</pre>'

It behaves in pretty much the same way that print_r() does.

Next up, dprint_r() is the equivalent of:
Code:
die('<pre>'.print_r($arr, TRUE).'</pre>');

On a bad day, I use these functions several hundred times, and it's saved me countless hours typing, so I though it might be useful to others.

Creating a dev helper might be a dumb idea, but I thought I'd ask just in case.


Messages In This Thread
dev_helper - by El Forum - 05-21-2009, 07:27 AM
dev_helper - by El Forum - 05-21-2009, 07:47 AM
dev_helper - by El Forum - 05-21-2009, 08:05 AM
dev_helper - by El Forum - 05-21-2009, 08:09 AM
dev_helper - by El Forum - 05-21-2009, 08:16 AM
dev_helper - by El Forum - 05-21-2009, 08:27 AM
dev_helper - by El Forum - 05-21-2009, 06:48 PM
dev_helper - by El Forum - 05-22-2009, 03:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB