dotkpay Posted May 17, 2011 Share Posted May 17, 2011 Is there a way or function that stops the execution of a required script but continues to execute the parent script, for example: if this is a.php <?php echo "<br>Good morning"; // function to stop execution of only this script to appear here echo "<br>Good Afternoon"; ?> and then this is b.php <?php require("a.php'); echo "<br>Good Evening"; ?> So if the file b.php is called it is supposed to display: Good morning Good evening So it has to skip "Good afternoon" because of the anonymous function which I need Quote Link to comment https://forums.phpfreaks.com/topic/236619-stop-executing-required-script/ Share on other sites More sharing options...
trq Posted May 17, 2011 Share Posted May 17, 2011 Put your code into functions and call what you need. Scripts execute from top to bottom without stopping. Quote Link to comment https://forums.phpfreaks.com/topic/236619-stop-executing-required-script/#findComment-1216428 Share on other sites More sharing options...
ambbarees Posted May 17, 2011 Share Posted May 17, 2011 Keep a.php code inside a function and call when you need it. Why do you wanna write the later part of the code in a.php if u don't want to execute it? Quote Link to comment https://forums.phpfreaks.com/topic/236619-stop-executing-required-script/#findComment-1216429 Share on other sites More sharing options...
PFMaBiSmAd Posted May 17, 2011 Share Posted May 17, 2011 You should not think of the required/included code as a separate script that is being 'called'. Think of it as source code (function definitions, class definitions, configuration information) that the main program needs to use to accomplish some goal. When the require/include statement in the parent script is executed, the required/included code is executed in the scope of the parent script. The required/included code might be stored in a separate file and in a different folder, but when it is executed, it is the same as if you had copy/pasted the source code from the required/included file into the parent script at the point where the require/include statement is at. Quote Link to comment https://forums.phpfreaks.com/topic/236619-stop-executing-required-script/#findComment-1216437 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.