counter += 1; return $this; } } (static function () : void { $factory = new AccessInterceptorScopeLocalizerFactory(); $foo = new FluentCounter(); $proxy = $factory->createProxy( $foo, [ 'fluentMethod' => static function (AccessInterceptorInterface $proxy, FluentCounter $realInstance) : void { echo "pre-fluentMethod #{$realInstance->counter}!\n"; }, ], [ 'fluentMethod' => static function (AccessInterceptorInterface $proxy, FluentCounter $realInstance) : void { echo "post-fluentMethod #{$realInstance->counter}!\n"; }, ] ); $proxy->fluentMethod()->fluentMethod()->fluentMethod()->fluentMethod(); echo 'The proxy counter is now at ' . $proxy->counter . "\n"; echo 'The real instance counter is now at ' . $foo->counter . "\n"; })();