PHP - Add method to a stdClass object
Posted: 02 May 2015, 06:51
How can I add a method to a stdClass object?
For example I try this code:
- but it generates this error:
For example I try this code:
Code: Select all
$ob = new stdClass;
$ob->prop = 'val';
$ob->site = function($dom) {
return 'http://'. $dom .'/';
};
echo $ob->site('coursesweb.net');
Code: Select all
Call to undefined method stdClass::site() in ..