Now, why not even do the definition and extension in one line of code? I will define a DotPHP class to help us contain it all within a nice namespace:
class DotPHP {
public static function defineClass($sClassName, $mBase=null) {
eval('class '.$sClassName.' extends Object {}');
if ($mBase) {
$sClassName::extend($mBase);
}
}
}
Now the all the code is done in a fewer lines of code:
DotPHP::defineClass('A', array(
'method3' => function($owner) { print 'method3'; }
));
DotPHP::defineClass('B', 'A');
print $o2->method3(); // output: method3
Please leave some feedback so that I know if you guys like the syntax.
No comments:
Post a Comment