We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

PHP Notice

I've notice the following notice inside my apps logs:

PHP Notice:  Cannot use a scalar value as an array in phalcon/http/response.zep on line 461 in ...

which is triggered by the following line of my code inside one of my controllers:

$this->response->redirect('mycontroller/myaction/' . $form->getEntity()->getHash(), false, 200);

Any idea, guys?



5.7k

What version of Phalcon are you using?



5.7k

What version of Phalcon are you using?

The version is 2.0.5.... While the PHP version is 5.4.23



5.7k

Here is what I've been able to gather as I look into this.

In the file phalcon/http/response.zep, line 461 is here:

https://github.com/phalcon/cphalcon/blob/phalcon-v2.0.5/phalcon/http/response.zep#L461

Have you tried changing your code 200 to something like 302,302 or 307 since that would be more accurate for the redirect? Or have you tried removing your status code from the redirect completely and let the framework handle it?

If not, give that a try and see if you're still getting the notice. Please post back with your results :-)

Also, can you update to 2.0.6 to see if you still receive that same notice. An update was pushed a few days ago.



5.7k

Steven, thanks for the reply. The idea is that I kinda need the 200 response code as the redirect occurs in a perfectly fine situation, after a POST request that was successfully performed and I need a redirect to a new (let's call it success) page. Why would that parameter be there if I can't use it? :) Also, the code line indicated by the warning makes no sense after you showed me the "internals".

However, I'll perform an update and I'll let you know.



5.7k

Unfortunatelly the notice is still there in version 2.0.6, but moved to line 481, which points to the same line of code:

https://github.com/phalcon/cphalcon/blob/phalcon-v2.0.6/phalcon/http/response.zep#L481

Did you tried with 303 HTTP response code? That's the most approporiate for redirects. And why would you use full HTTP redirection anyway when all you need to do is dispatch your application flow to another method / controller?