How do I add a new method to an object \"on the fly\"?
$me= new stdClass;
$me->doSomething=function ()
{
echo \'I\\\'ve done something\';
};
$me->
There's a similar post on stackoverflow that clears out that this is only achievable through the implementation of certain design patterns.
The only other way is through the use of classkit, an experimental php extension. (also in the post)
Yes it is possible to add a method to a PHP class after it is defined. You want to use classkit, which is an "experimental" extension. It appears that this extension isn't enabled by default however, so it depends on if you can compile a custom PHP binary or load PHP DLLs if on windows (for instance Dreamhost does allow custom PHP binaries, and they're pretty easy to setup).