-
Notifications
You must be signed in to change notification settings - Fork 38
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
Optional parameters do not work with PHP 7.1 syntax #37
Comments
There are tests covering that: https://github.com/PHP-DI/Slim-Bridge/blob/master/tests/RoutingTest.php#L46-L74 You may be onto an edge case. Can you try without the |
I asked my teamate @anologicon to test it. |
👍 Works: class SomeController {
function someAction($request, ?int $id = null) {}
} class SomeController {
function someAction($request, int $id = null) {}
} 👎 Doesn't Works: class SomeController {
function someAction($request, ?int $id) {}
} Exception :
|
Hi there, I'm facing the same issue with optional parameters. Here is a sample of my non-working code: class ClassController
{
public $mProxy;
public function __construct(?Proxy $proxy = null)
{
$this->mProxy = $db ?? ProxyFactory::create();
}
} And this is the working sample of code: class ClassController
{
public $mProxy;
public function __construct(Proxy $proxy)
{
$this->mProxy = $db ?? ProxyFactory::create();
}
} As I understand so far, the '?' (question mark) has no meaning to PHP-DI as the behaviour is the same whether I use it or not. My problem appears only when I write Would it be possible to have a workaround ? or even more appreciated, a fix ? Thanks |
Hi, I haven't had time yet to work on that. However a pull request would be welcome. |
Thanks a lot for the quick answer, it's much appreciated ! In the meantime though, here is a temporary fix I am using from PHP-DI repo : I've written a factory used only in my unit test to solve this issue. Hope this will help someone in my case until a fix will show up :-) |
Fixed by PHP-DI/Invoker#29 |
Example:
Or:
These examples does not works, the injector throws an error saying that there's no given value for that parameter. As long as it's optional, something like null should be injected as the value.
The text was updated successfully, but these errors were encountered: