-
-
Notifications
You must be signed in to change notification settings - Fork 116
Description
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