[js.php] A JavaScript Object Like PHP Class
PHP 5.3 introduces the Closure class which is really useful and more powerful than good old lambdas via create_function . These are main limits of Closure class: you cannot serialize a Closure instance (and json_encode does not solve the problem at all) you cannot inject scopes via $this unless the closure comes from a class method While with an emulated prototype style class, something I tried months ago as well, the first point could not be a problem, to solve the second one is quite inevitable to use a Python like variable as first argument, called $self , to make the Closure both portable and re-adaptable. JSObject :: JavaScript Object Like PHP Class /** js.php basic JSObject implementation * @author Andrea Giammarchi * @blog WebReflection.blogspot.com * @license Mit Style License */ class JSObject implements ArrayAccess { // public static prototype static public $prototype; // ArrayAccess Interface public function offsetExists($index){return isSet(...