Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
public function set($name, $value = null)
Impossible to define explicitly a null value:
so it will create a
One solution would be to check the numbers of arguments given: if
Another would be to return a more generic helper that would allow:
but that seems complex because of how it currently works with the
Finally, by adding a
$container->set('service', new NullValue());
// Will set a null value $container->set('foo', null); // Will return a ClassDefinitionHelper for inline definition $container->set('foo')->addParameter(/* ... */);
As a consequence:
// Will not do anything as such $container->set('foo'); // Will throw an exception (because set returns null) $container->set('foo', null)->addParameter(/* ... */);
In the YAML definitions, parameters are always references to other entries, so as you guessed:
My\Implementation: constructor: param: null
will look for an entry for the name "null" in the container.
I just learned that YAML supports null value, and in different forms. Apparently, you can use any of this:
nullparam: null nullparam: ~ nullparam:
The question now is: does PHP-DI supports it on its end. I must confess I haven't tried it, and there are no tests for this. Given your last suggestion is valid YAML, if you have tried it and it doesn't work, then it's a bug.
Could you confirm that any of the 3 solutions above don't work?