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.
#2

[eluser]Dam1an[/eluser]
I actually use a template in Eclipse which expands pprintr to your first snippet and then jumps to the position for me to put in the array Smile

Another (potentially) useful dev helper I've seen around before is the lorem ispum one which uses the lipsum API to give a given number of paragraphs/sentances/words/characters
#3

[eluser]TheFuzzy0ne[/eluser]
If it's the one I'm thinking of, then that was [url="http://ellislab.com/forums/viewthread/78114/"]one of the first helper projects I wrote and published in the community[/url]. It needs a rework, because at the current time it just grabs some text straight from http://www.lipsum.com/, when really it should be cached.
#4

[eluser]Dam1an[/eluser]
Indeed, that is the one I was refering to (didn't remember it was you that published it though)
Take it you haven't had the time to make the improvements? If not, I might have a go in my spare time (although if I done it, it would all be self contained instead of using the API so you can use it when developing offline (which I do quite a lot)
#5

[eluser]TheFuzzy0ne[/eluser]
My next step was to make it generate the text itself, but I was hoping the source code for the one on the lipsum.com Web site would just fall on to my lap, but sadly, this has yet to happen. I have many theories about how they do it, but unfortunately none of those can be proven.
#6

[eluser]Dam1an[/eluser]
A very quick Google resulted in these "dropping on my lap" Wink

http://www.charles-reace.com/PHP_and_MySQL/Lorem_Ipsum/
and
http://johno.jsmf.net/knowhow/ngrams/index.php (source link at the end)

They should give you some ideas (looking through the first one, its a very simple implementation)
#7

[eluser]Colin Williams[/eluser]
It also helps to wrap print_r() in htmlspecialchars()
#8

[eluser]TheFuzzy0ne[/eluser]
Great idea. Thanks, Colin.




Theme © iAndrew 2016 - Forum software by © MyBB