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
Weird behaviour with PHP 7.1 nullable types #452
Comments
Thanks for the report, so just to get this right: you get the error for parameters that are nullable with Maybe |
yes, I get errors when the params are nullable, indicated by the
I'm only using PHP-DI using the ->make() method, so I can't comment on what I would want auto-injecting. But in my case, because I'm using make and passing params, I have been able to verify that the params passed are valid. I hope that makes sense, it's a difficult issue to describe because it isn't easy to consistently reproduce. |
If it's any help, I also came up against an issue in a separate library which was also triggered by the use of the new nullable param feature. Perhaps there's a common library you share with that classtools which causes the issue, or similar? |
@mnapoli I think you need to use |
I'll be able to provide some examples in a few days - I'm slammed with a deadline at the moment, but after that passes tomorrow or Tuesday, I'll put together examples that demonstrate the bug. :) |
I've pushed a test to cover PHP 7.1 nullable types, I'll close this issue unless we hear about it again. |
PHP 7.1 introduces nullable Types to be used when type-hinting: https://wiki.php.net/rfc/nullable_types
I'm finding that sometimes, PHP-DI will throw an error when I have a class construct signature which makes use of nullable types, e.g:
It seems that adding = null, e.g
?OptionalThing $optional_thing = null
is the only way to get past this error.It seems that the behaviour is somewhat random, sometimes it occurs if the param is the last in the method signature, sometimes if other params in the method have default values, e.g:
int $another_thing = 0, ?OptionalThing $optional_thing
Here's the error I see, with class names replaced:
The text was updated successfully, but these errors were encountered: