3v4l.org

run code in 300+ PHP versions simultaneously
<?php class User { } class UserProvider { public function getServices() { return ['user']; } public function user() { return new User(); } } $provider = new UserProvider(); $services = array_map(function($factoryName) use($provider) { return $provider->{$factoryName}(); // <-- dynamic call }, $provider->getServices()); var_dump($services);

preferences:
24.04 ms | 405 KiB | 5 Q