0

I am using Codeigniter for a project and i usually call a series of models (let's say controllerA -> modelA -> modelB -> modelC) for some work. I want the php to stop executing when it reaches some exception where i invoke the exit() command. Now, if the command exit() is invoked in modelB, will it stop execution of only the script of modelB and continue executing rest of the modelA? Or will it stop the entire execution flow.

I really don't know how to put this question here. The question looks quite messy. Please let me know should i need to revise the question itself.

3
  • 1
    It should stop after modelB exit. But you can try exit in Model B and echo 'something' in modelC. Commented Mar 28, 2012 at 7:27
  • okay........ that's a great suggestion....... i will try that and post here. Commented Mar 28, 2012 at 10:40
  • right......... it stops at modelB Commented Mar 29, 2012 at 13:47

5 Answers 5

6

Yes, exit stops all script execution immediately, regardless where you call it.

The opposite is return which only stops execution of the current function (or current file when used at global level in an included file)

Read more here: https://stackoverflow.com/a/9853554/43959

Sign up to request clarification or add additional context in comments.

Comments

2

Wherever you call the exit() function, all code will stop executing. This includes the other files because codeigniter just 'requires' them.

Comments

2

It stops the execution from that line.

Comments

0

I'm not sure if what you want, but maybe you can use exceptions to control PHP code execution.

http://es.php.net/manual/en/class.exception.php

Regards!

Comments

0

Like someone mentions above you should return from a function, or If your in a loop you could use continue or break

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.