Jump to content

Run code at end of execution?


RDFrame

Recommended Posts


Is there any way in PHP to run some code at the end of every execution? I don't mean just placing the code at the bottom of the script, because that won't work with this. For example, in Perl there's the BEGIN { } and END { } constructs. Every time that Perl program finishes execution, whatever code is between END { } will be ran.

For example, if exit() is called somewhere in the PHP program, I still want a small block of code to be executed. Is there any way to do this in PHP? I looked through the manual, but couldn't find anything. Or is this not supported by PHP?

Thanks,
Matt
Link to comment
Share on other sites

a few possibilities.
Try and put the exit function in side the bracket you want to close, and then start up a nother one, or you could try sleep, and unsleep instead, but I think that will be a different affect. The only other idea I had was, like people told me on here maybe you could keep a variable and start it as true at the top, and then don't use the variable at all then after the kill statemtn, you could say if whatever is true, then continue your code, but then again if kill ends the script I don't see how it will make it to the end. You could use or die
I don't know if sql will work though when randomly thrown in throughout php, but it's worth a thought.
Link to comment
Share on other sites

You can place PHP code within the parentheses inside the exit function, or you can create a function which contains the code that you want to be run you call the exit function like so:
[code]function exitFunc() {
    // do something here, when you exit the script
}

exit(exitFunc());[/code]
Does that help?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.