exclude private property from print_r or object?

Posted by Hailwood on Stack Overflow See other posts from Stack Overflow or by Hailwood
Published on 2012-11-21T03:47:10Z Indexed on 2012/11/21 5:00 UTC
Read the original article Hit count: 203

Filed under:
|
|
|
|

Basically I am using Code Igniter, and the Code Igniter base class is huge, when I print_r some of my objects they have the base class embedded inside them. this makes it a pain to get the information I actually wanted (the rest of the properties).

So, I am wondering if there is a way I can hide, or remove the base class object?

I have tried

clone $object;
unset($object->ci);
print_r($object);

but of course the ci property is private.

the actual function I am using for dumping is:

/**
 * Outputs the given variables with formatting and location. Huge props
 * out to Phil Sturgeon for this one (http://philsturgeon.co.uk/blog/2010/09/power-dump-php-applications).
 * To use, pass in any number of variables as arguments.
 * Optional pass in "true" as final argument to kill script after dump
 *
 * @return void
 */
function dump() {
    list($callee) = debug_backtrace();
    $arguments = func_get_args();
    $total_arguments = count($arguments);
    if (end($arguments) === true)
        $total_arguments--;

    echo '<fieldset style="background: #fefefe !important; border:2px red solid; padding:5px">';
    echo '<legend style="background:lightgrey; padding:5px;">' . $callee['file'] . ' @ line: ' . $callee['line'] . '</legend><pre>';

    $i = 0;
    foreach ($arguments as $argument) {
        //if the last argument is true we don't want to display it.
        if ($i == ($total_arguments) && $argument === true)
            break;

        echo '<br/><strong>Debug #' . (++$i) . ' of ' . $total_arguments . '</strong>: ';

        if ((is_array($argument) || is_object($argument)) && count($argument)) {
            print_r($argument);
        } else {
            var_dump($argument);
        }
    }

    echo '</pre>' . PHP_EOL;
    echo '</fieldset>' . PHP_EOL;

    //if the very last argument is "true" then die
    if (end($arguments) === true)
        die('Killing Script');
}

© Stack Overflow or respective owner

Related posts about php

Related posts about oop