User Contributed Notes 7 notes

if you want a Dynamic class you can extend from, add atributes AND methods on the fly you can use this:<?phpclass Dynamic extends stdClass{ public function __call($key,$params){ if(!isset($this->{$key})) throw new Exception("Call to undefined method ".get_class($this)."::".$key."()");$subject = $this->{$key};call_user_func_array($subject,$params); } }?>

If you call var_export() on an instance of stdClass, it attempts to export it using ::__set_state(), which, for some reason, is not implemented in stdClass.

However, casting an associative array to an object usually produces the same effect (at least, it does in my case). So I wrote an improved_var_export() function to convert instances of stdClass to (object) array () calls. If you choose to export objects of any other class, I'd advise you to implement ::__set_state().

Note: This function spits out a single line of code, which is useful to save in a cache file to include/eval. It isn't formatted for readability. If you want to print a readable version for debugging purposes, then I would suggest print_r() or var_dump().