DEV Community

Discussion on: What is your favourite function()?

Collapse
 
pilskalns profile image
Andžs

In PHP I always include file with my custom helper functions. These two wrap output with <pre/> tags, which allows nice&quick debugging via browser from any class or template code.


function pre($obj = null, $escape = false){
    echo "<pre>";
    if($escape){
        $obj = htmlspecialchars ( print_r($obj, true) );
    }
    print_r($obj);
    echo "</pre>";
}

function dump($obj = null){
    echo "<pre>";
    var_dump($obj);
    echo "</pre>";
}
Collapse
 
dfellini profile image
Dan Fellini

HA! I have a pre() function too! I use it many, many times a day. Mine has the $obj, but then a title, so if I have multiple pre()s going, I know which is which. Like, pre( $obj, 'This is the user obj');
Love it.

Collapse
 
jjjjcccjjf profile image
endan

var_masterpiece is also an excellent browser extension too for debugging!