lighttpd forum php-shell > Alternative display function for classes

Posted by valhallasw (Guest)
on 22.03.2008 23:23
As classes often have recursive links (and give bloated outputs), I 
wrote a simple __shell_print_var script that, instead of the object 
dump, shows the type and an hash of the serialized version:

function __shell_print_var($data, $verbose) {
  if (is_object($data)) {
    print get_class($data) . " [" . hash('crc32b', serialize($data)) . 
"]\n";
    if ($verbose) {
      print_r($data);
    }
  } else {
    var_export($data);
  }
}


>> Doctrine_Manager::connection('mysql://(...)');
Doctrine_Connection_Mysql [8285279d]
>> $a = new User();
User [e5b12458]

Especially when using larger classes this is handy, because assignments 
return the value... and you really don't want three pages of class dump 
per line of input :)
(Feel free to reproduce this code, it's public domain as far as I am 
concerned ;))