Skip to content
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

Incompatibility with PHP 7.1 - type-hint "iterable"not accept "array" or "Traversable" #203

Closed
michalhujo opened this issue Oct 21, 2018 · 0 comments

Comments

@michalhujo
Copy link

@michalhujo michalhujo commented Oct 21, 2018

Version: 2.4.12

Bug Description

In presenter methods like actionXYZ or renderXYZ I can't use iterable parameter type-hint, because if I put argument type array or ArrayHash (or another object that implements interface Traversable) I get InvalidLinkException (if I try create link) or BadRequestException (if I try call method direct with typing URL) with this message:

Argument $data passed to App\Presenters\SamplePresenter::actionSample() must be iterable, Nette\Utils\ArrayHash given.

respectively

Argument $data passed to App\Presenters\SamplePresenter::actionSample() must be iterable, array given.

Exception is thrown from Nette\Application\UI\ComponentReflection after ComponentReflection ::convertType returns false

Steps To Reproduce

declare(strict_types=1);

class SamplePresenter extends Nette\Application\UI\Presenter
{
    public function actionSample(iterable $data): void
    {
        foreach($data as $item) {
            // some logic
        }
    }
    public function actionRedirectToSampleWithArray(): void
    {
        $data = ['a', 'b', 'c'];
        $this->redirect('sample', $data);
    }
    public function actionRedirectToSampleWithTraversable(): void
    {
        $data = Nette\Utils\ArrayHash::from(['a', 'b', 'c']);
        $this->redirect('sample', $data);
    }
}

Expected Behavior

I expect true return value from Nette\Application\UI\ComponentReflection::convertType in accordance with PHP documentation:

Iterable is a pseudo-type introduced in PHP 7.1. It accepts any array or object implementing the Traversable interface. Both of these types are iterable using foreach and can be used with yield from within a generator.

http://php.net/manual/en/language.types.iterable.php

@dg dg closed this in e9a0f67 Oct 25, 2018
dg added a commit that referenced this issue Nov 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.