3v4l.org

run code in 300+ PHP versions simultaneously
<?php // I declare that MyService needs two Parameters, one: an object, two: a scalar value class MyService { public function __construct(AnObject $service, $value) { $this->service = $service; $this->value = $value; // pretty common right? } } // Now, in my controller, I simply want to be able to DI the MyService object automatically, but it requires a value, so I can't do that // instead, I'll either have to use a SETTER (which I dont' want to, because my library NEEDS $value as a constructor parameter and I'm not changing it), or a factory. Here's what I'll have to do with a factory: class MyServiceFactory { public function build($value) { return $provider->make(MyService, [':value' => $value]); } } // Now I DI this service factory into my controller... class Controller { public function indexAction(MyServiceFactory $factory, Request $req) { $userSuppliedValue = $request->getValue('postValue'); $factory->build($userSuppliedValue); // Note how the $userSuppliedValue, that MyService needs as a constructor parameter, ISNT KNOWN until INSIDE the function I'm already asking it to be DI'd into? } }
Output for git.master, git.master_jit, rfc.property-hooks

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
41.52 ms | 401 KiB | 8 Q