Humpty Posted August 31, 2007 Share Posted August 31, 2007 G'day Guys, Here is a Query from a quer bloke: (Visualising VB code structure in my head as I type this) I want to create a code block, Sub, Function whatever you want to call it. I want to exit that block but still permit the PHP script to run. (Example Ideal World: Use a whole bunch of Includes with the ability to use exit(); without stopping the main script.) I'm after either a push in the right direction or a recomendation on a way to do this. At this stage all I can think of is to use continue; and place all my code in a loop which loops once. If this post is a little too Dr. Seuss please let me know and I will try to reword it. Thanks - humpty Quote Link to comment https://forums.phpfreaks.com/topic/67443-best-way-to-exit-code-blocks/ Share on other sites More sharing options...
hostfreak Posted August 31, 2007 Share Posted August 31, 2007 If your using a function, look into http://www.php.net/manual/en/function.register-shutdown-function.php Quote Link to comment https://forums.phpfreaks.com/topic/67443-best-way-to-exit-code-blocks/#findComment-338544 Share on other sites More sharing options...
Humpty Posted August 31, 2007 Author Share Posted August 31, 2007 I'm not using a function, however does seem like a good avenue to follow for what I want. (basically want the equivelent of calling a sub and exiting that sub without exiting the program) Quote Link to comment https://forums.phpfreaks.com/topic/67443-best-way-to-exit-code-blocks/#findComment-338547 Share on other sites More sharing options...
MadTechie Posted August 31, 2007 Share Posted August 31, 2007 personally i think you mean break for a loops, switch or if, but if you just want to exit the funtion why not use return ? Quote Link to comment https://forums.phpfreaks.com/topic/67443-best-way-to-exit-code-blocks/#findComment-338548 Share on other sites More sharing options...
Humpty Posted August 31, 2007 Author Share Posted August 31, 2007 ... but if you just want to exit the funtion why not use return ? That was exactly the point, I wasn't in a function to start with. That does seem like the best way to go though. A function with no variables will just as well as a function with variables, and on the same side of the fence there is no need to return any values etc, just use return to exit that function. That is what I was looking for, seems like it would be the best and closest thing to a sub. Thanks dudes. (will leave topic unsolved for a bit in case someone comes up with somethign else) Quote Link to comment https://forums.phpfreaks.com/topic/67443-best-way-to-exit-code-blocks/#findComment-338551 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.