Fondamentalmente sto usando Code Igniter e la classe base Code Igniter è enorme, quando stampo alcuni dei miei oggetti hanno la classe base incorporata al loro interno. questo rende difficile ottenere le informazioni che effettivamente desidero (il resto delle proprietà).esclude la proprietà privata da print_r o oggetto?
Quindi, mi chiedo se c'è un modo per nascondere o rimuovere l'oggetto della classe base?
ho cercato
clone $object;
unset($object->ci);
print_r($object);
ma ovviamente la proprietà c'è privato.
la funzione reale che sto usando per il dumping è:
/**
* 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');
}
Ma voglio che le altre proprietà private, solo che non voglio che una proprietà – Hailwood
@Hailwood provare ora, un po 'modo hacky, ma potrebbe lavoro. – arma
Ma 'get_object_vars()' si aspetta un oggetto come parametro. '$ class_of_object' è una stringa. – TheFox