Add Comment
|
Related Links
|
TrackBack
Quick Way to Circumvent "exit" CallRecently I came across some PHP codes where the developer(s) of the code littered "exit" all through out, where errors/exceptions/failures occur. (This technique seems to be the trend for many MySQL/PHP software as well.) That technique made the code difficult to extend and embed into other functionality, because PHP execution would stop immediately upon encountering the "exit" call. The best solution is to re-architecture the execution flow with structured programming and eliminating all "exit" calls. However, that will be an expensive expenditure for this pre-existing software. Luckily with PHP 5.3, there is an easy way out. The easy way is to use the "goto" statement with a label. (Yes. I know "goto" is a taboo against structured programming. And for once in my life, I am grateful that it is a part of PHP 5.3 and later.) By placing a "end:" label at the end of the source code execution (each source file), a simple search-and-replace of "exit;" with "goto end;" did the trick. Chieh Cheng
Add Comment
|
Related Links
|
TrackBack
Did your message disappear? Read the Forums FAQ. Add CommentSpam Control | * indicates required field TrackBackTrackBack only accepted from WebSite-X Suite web sites. Do not submit TrackBacks from other sites. Send Ping | TrackBack URL | Spam Control No TrackBacks yet. TrackBack can be used to link this thread to your weblog, or link your weblog to this thread. In addition, TrackBack can be used as a form of remote commenting. Rather than posting the comment directly on this thread, you can posts it on your own weblog. Then have your weblog sends a TrackBack ping to the TrackBack URL, so that your post would show up here. Messages, files, and images copyright by respective owners. |
Products
|
Services
104 Users Online
|
Copyright © 1996 - 2024. All Rights Reserved. |