PHP Flow Control / Terminate & Capture pt. 1
Subtitles of the Movie
In this lesson I'm going to show you how you can terminate your PHP script and how you can capture this current status of your application. Here in our 0305.php file, we have some code left over from our previous lesson where we had a nested loop and then we have an output that goes to the browser. Let's view this code in our browser so that we can modify it and then compare the results. Here we have our loop iterations and then we have our final output to the browser. Now let's go ahead and exit the script by using the exit command. We refresh the browser and we lost our final output because the script was halted at the time that we placed the exit statement. The PHP exit statement works exactly like FileMaker Pro's halt script step. It completely halts this script and any other calling script and sends whatever output has already been stated to the browser. You use the exit script step when you know that you don't want to continue on with anymore PHP code. The exit script step will stop any sort of output to the browser, including any HTML code that continues on after it. For instance, if I had HTML code posted down here, and I go to refresh this in my browser, when I hit refresh, again, I don't get any sort of HTML output at all. The exit script step will stop any other output to the browser and the web server will take any output that was up to that point and send it straight to the user. Another way to kill your script is with the die function. Now, the die function is a little bit different in exit in that it allows you to pass a parameter. You can pass a string parameter and PHP will send this to the browser at the time that it terminates the script. When I hit refresh, you can see that we got our string parameter. The die function is used most commonly when you're trying to debug your program. It works great because you can place the die function anywhere inside of your PHP logic and capture a current state of the application. We could say we killed this script when X was equal to X. What PHP will do is terminate the script when the die function is reached, but output whatever string we passed to it to the browser. Using the die function allows you to capture the current status of running variables and so forth in your PHP application, send them to the browser and then terminate its execution. Normally you don't use the die function in a production application, but it works great for troubleshooting.
Tutorial Information
| Course: | FileMaker 9 & PHP Foundations |
| Author: | Lance Hallberg |
| SKU: | 33786 |
| ISBN: | 1-933736-99-2 |
| Release Date: | 2007-08-22 |
| Duration: | 9.5 hrs / 107 lessons |
| Work Files: |
Yes |
| Captions: | For Online University members only |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 81,350 Video Tutorials (20,800 free)
- Video Available as Flash or QuickTime
- Over 782 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 