Code snippets for symfony 1.x

Navigation

Refine Tags

Snippets tagged "object variables"

debug objects or variables...

my approach to the previous snippet is to create a class called debugTools.class.php and throw it in the \lib directory. It should contain the following code:

<? 
 
Class debugTools {
 
/**
* renders to the page a proper object map for looking over contents of an object as it occurs.
*
* @param    object       $object        (required) the object for inpection
*/
Public Static function inspect($object)
    {
    echo "<PRE>";
    print_r($object);
    echo "</PRE>";
    }
 
 
}// ends class  
?>

you can then call it easily (with only two or three keystrokes if your IDE does autocompletion) by calling:

echo debugTools::inspect($object);

the resulting formating looks like so (i used it to analyze a usp shipping object):

ups Object
(
    [_errors] => Array
        (
        )
 
    [_action] => 3
    [_delivery_code] => GND
    [_src_country] => US
    [_dst_country] => US
    [_rate_chart] => 5
    [_container] => 0
    [_rescom] => 1
    [_rate_charts] => Array
        (
            [0] => Regular+Daily+Pickup
            [1] => On+Call+Air
            [2] => One+Time+Pickup
            [3] => Letter+Center
            [4] => Customer+Counter
            [5] => Drop+Off
        )
 
    [_containers] => Array
        (
            [0] => 00
            [1] => 01
            [2] => 21
            [3] => 22
            [4] => 23
            [5] => 1
            [6] => 2
        )
 
    [_rescoms] => Array
        (
            [0] => 1
            [1] => 2
        )
 
    [_src_zip] => 97499
    [_dst_zip] => 90120
    [_weight] => 2
)

a handy way of viewing objects that can be accessed from the layout or pretty much anywhere, if you're new to symfony use it to look over $sf_user in the template, you will have a much better idea what's going on.

by Russ Cann on 2006-06-02, tagged debug  object  variables 
(1 comment)