Nette 3 redirect error
BigOHenry opened this issue · 5 comments
Hello
Trying to clean phpstan lvl5 errors after upgrade to Nette 3. I am still getting these errors and really dont know what to do (i tried to ignore it, but problem is #2 in error for me)
Parameter #2 $destination of method Nette\Application\UI\Component::redirect() expects string|null, array<string, int> given.
Parameter #2 $destination of method Nette\Application\UI\Component::redirect() expects string|null, array<string, mixed> given.
Any idea how to 'fix' this error or how to add it to exceptions?
The best approach would be to fix the phpDoc in Nette itself. Can you send a PR there?
I think its not that easy. There is some back compatibility stuff:
/**
* Redirect to another presenter, action or signal.
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
* @param array|mixed $args
* @throws Nette\Application\AbortException
*/
public function redirect($code, $destination = null, $args = []): void
{
if (is_numeric($code)) {
trigger_error(__METHOD__ . '() first parameter $code is deprecated; use redirectPermanent() for 301 redirect.', E_USER_DEPRECATED);
if (func_num_args() > 3 || !is_array($args)) {
$args = array_slice(func_get_args(), 2);
}
} elseif (!is_numeric($code)) { // first parameter is optional
$args = func_num_args() < 3 && is_array($destination) ? $destination : array_slice(func_get_args(), 1);
$destination = $code;
$code = null;
}
$presenter = $this->getPresenter();
$presenter->redirectUrl($presenter->createRequest($this, $destination, $args, 'redirect'), $code);
}
If it was on me, i will remove $code variable completely.
The problem is that $destination can be string|array, right?
$this->getPresenter()->redirect(':Home:'); // this is OK
$this->getPresenter()->redirect(':Home:', ['name' => $name]); // there is an error
So yeah, can be string|array. To be precise it can be only array|null, because if i write $this->getPresenter()->redirect(200, ':Home:', ['name' => $name]); i will get this error first parameter $code is deprecated.
OK, i will start issue at nette/application if can be some how fixed (removed $code or fixed typehints)
Thank you for your time :)
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.