-
-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impossible do define "null" value #79
Comments
Fixed. // 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(/* ... */); |
How does this work in YAML? I have tried variations of:
and
and
|
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: (see also http://yaml.org/type/null.html or symfony/symfony#7274) 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? |
I tried all three. I get the following exception in all three cases:
|
Thanks, I have created a new issue for this: #95 |
Thanks! If this is something that you dno't have time for I can also devote a little time to debugging this today... |
thanks, feel free to submit a pull request. If you have time only to write tests to reproduce it that's good too. FYI I may not have a lot of time to look at it in the next days. |
Impossible to define explicitly a null value:
because:
so it will create a
ClassDefinition
for the entry name ("service" in the example).One solution would be to check the numbers of arguments given: if
$value
was given and specified explicitly tonull
, then we define a null value.Another would be to return a more generic helper that would allow:
but that seems complex because of how it currently works with the
ClassDefinitionHelper
.Finally, by adding a
NullValue
class:The text was updated successfully, but these errors were encountered: