vdegenne
vdegenne

Reputation: 13298

how to stop the current included execution in PHP?

I know it sounds a bit hacky but is there a way of stopping the execution of an included script in php ? Giving this example here

end script

Is there a function or a tiny trick to use to have this effect here ?

note 1 : I know b.php in the example has a closed conditional structure but if there is code after that structure It will get executed.

note 2 : exit will stop the whole php running execution, that is not what I need.

Upvotes: 1

Views: 1020

Answers (1)

Barmar
Barmar

Reputation: 782148

You can use a return statement in the included file to return to the file that includes it.

From the documentation of include:

It is possible to execute a return statement inside an included file in order to terminate processing in that file and return to the script which called it.

Upvotes: 10

Related Questions