4

Is it possible to do this?

$objetc -> runAndFinish();

echo "this should not be echoed";

instead of this?

$objetc -> runAndFinish();

exit();

echo "this should not be echoed";

So runAndFinish(); method would somehow end the script processing. Is it possible?

1
  • 12
    Yes. Just put the exit(); or die(); statement into the runAndFinish() method. Did you even try this before you asked the question? Commented Jan 12, 2011 at 16:48

4 Answers 4

11

Put an exit(); inside of your classes runAndFinish(); method

class someClass{
  function runAndFinish(){
     exit();
  }
}

$obj = new someClass();
$obj->runAndFinish();
echo "not gonna print";
Sign up to request clarification or add additional context in comments.

Comments

5

Put the exit call in the method and it will exit during its call

Comments

1

If you are in a class you can use:

if($condition)
{
return;
}

Comments

0

Yes, of course it's possible. It you put exit() or die() (or something else that might end execution) in that particular method and it will execute.

To my knowledge, there aren't any special restrictions for what you can execute in a methods vs. anything else.

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.