De klasse: [code=php] $v) { $out[self::escape($k)] = self::clean($v); // $v might be anything, call clean() again } $in = $out; } elseif (is_numeric($in)) { $in = '(numeric) '.$in; // no cleaning necessary } elseif (is_bool($in)) { $in = '(bool) '.($in ? 'true' : 'false'); // print boolean value as string } elseif (is_object($in)) { // Convert object to string using print_r. $in = '(object) '.self::escape(print_r($in, true)).''; } elseif (is_null($in)) { $in = '(null)'; } elseif (is_resource($in)) { $in = '(resource)'; // @todo add more info? } elseif (is_string($in)) { $in = '(string) '.self::escape($in); } else { // something we missed $in = '(something)'; } return $in; } public static function dump($in, $file='', $line='') { if (!empty($line) && !empty($file)) { echo 'variable dump in file '.$file.' on line '.$line.''; } else { echo 'variable dump'; } if (is_array($in)) { echo '
'.print_r(self::clean($in), true).'
'; } else { echo '
'.self::clean($in).'
'; } } } // class ?> De klasse heeft één publieke methode (dump) die je op twee manieren kunt aanroepen: ofwel met één parameter, waarbij je de te dumpen variabele meegeeft, ofwel met drie parameters, waarbij de tweede en derde parameters (respectievelijk) de "magische constanten" __FILE__ en __LINE__ bevatten. Hiermee kun je zien waar (in welk script) en op welke regel de dump methode is aangeroepen. Dit kan handig zijn als je op een moment meerdere dumps in je code hebt staan om te zien welke wordt uitgevoerd. Voorbeeld: [code=php]test = $test; } } // Test variable. $test = array( 'a' => array( // subarray 1 => "", // nasty code 2 => false, // a boolean 77 => true, // another boolean 3 => '5.6666667', // a numeric value stored as string 'object' => new Test('hallo'), // an object 4 => 1.2, // a numeric value (float) 5 => 7, // a numeric value (integer) 6 => array( // subsubarray 'z' => 'bold', // more nasty code 'a' => 'asdf', // a string ' 'hai', // nasty key ), 9 => null, ), '' => 'lala
', // key with code in it '<b>' => 'hoi', // escaped variant of previous key, which should not be overwritten by your dump functionality... ); // Dump the evil code in a safe way. Debug::dump($test, __FILE__, __LINE__); ?>