I have built a REST API in PHP that, in several cases, uses an exit() statement to prevent the script from continuing for various reasons.
This works well when I’ve been making calls to it using a JavaScript fetch.
I have now come across a case where I need to use this API in a PHP file on the same server. I know that I could use ‘include’, but this means that if an exit() statement is triggered, my entire script will stop running.
My API is quite extensive and so I’d prefer not to make edits to it (I know that I could replace exit with return for instance, but many of the exits in my API are called inside functions meaning that a return wouldn’t have the desired effect.)
Is there a better way to access my API in PHP than include? Or some way to get around this? Thank you.
1