Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Schwabbe's avatar

return "back()" or "redirect()" doesn't stop the main function execution

So, in a public function I am calling a method like this $this->checkStripe(), within this function there are some if's and each of them contain some session()->flash() and the return back() or redirect(), but the thing is that when executed the return back() or redirect() doesnt stop the main function execution, it just gets out of the checkStripe();

What's in if():

session()->flash('message', '* Please create a Stripe Account first, before changing the Fee to Paid!');
session()->flash('status', false);
return back();
0 likes
4 replies
Snapey's avatar

back is not some magic method that whisks you off somewhere else.

Your return goes back to whatever called checkStripe()

If that caller is not expecting a redirect as a response, then it will just ignore it.

Schwabbe's avatar

@snapey So, you have a solution? What do you suggest, how can I stop execution and redirect to a view within that if()?

Snapey's avatar
Snapey
Best Answer
Level 122

You have to throw an exception or return a value that the calling code can detect and handle.

Please or to participate in this conversation.