Refactored so the extension can be used in PHP 5.3 as well. Fixes issue #172

PHP 5.4 can handle $this in a closure, but PHP 5.3 can't. Made compatible.