1

When I post data to a function in php page, it continues to run over all lines. I mean while debugging I retrieve my data with echo json_encode(..) And continue in next line to debug. So I use exit to stop it. But it means I have to use exit each echo..

 echo json_encode($resultData);
                exit; //if I don't use this, interprets goes on

In real scenario, I though it will improve performance because I don't need php interpreter check the other lines.. or I have misunderstood completely on this?

6
  • And the problem is ? Commented Jun 17, 2015 at 13:24
  • if the job is done then why other lines? Commented Jun 17, 2015 at 13:25
  • @Alex the problem is I wonder Do I have to use exit with echo to send data to client. or is there any more reliable way like in .NET simply "return" Commented Jun 17, 2015 at 13:26
  • 1
    @MehmetYenerYILMAZ exit stop the script running further...To send data to client there are too many possible ways. Commented Jun 17, 2015 at 13:28
  • 1
    @MehmetYenerYILMAZ if you want to return data in your function just use return json_encode($resultData); Commented Jun 17, 2015 at 13:30

2 Answers 2

2

To direct the result to the calling function use return json_encode($resultData);

If just want to output your results use

echo json_encode($resultData);
return false;
Sign up to request clarification or add additional context in comments.

Comments

0

To make it with one function you can use exit() or die() instead of echo + exit, for example:

exit(json_encode($resultData));

or

die(json_encode($resultData));

They are equivalent to each other, but die is one character shorter.

Comments

Your Answer

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