How to add a new method to a php object on the fly?
Posted
by MadBad
on Stack Overflow
See other posts from Stack Overflow
or by MadBad
Published on 2010-05-30T08:49:12Z
Indexed on
2010/05/30
8:52 UTC
Read the original article
Hit count: 185
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->doSomething();
//Fatal error: Call to undefined method stdClass::doSomething()
© Stack Overflow or respective owner