Usually, this method is not called in a loop, but if it is, there is one thing that may be EXTREMELY important to think of, and that is to run `restore_error_handler()` once for each call to `set_error_handler`. Otherwise, you will have a memory leak. Every time set an error handler, even if it's identical to the previous one, you're pushing the previous one to a stack.
We recently had a big crash due to this, and we had a very hard time finding out what the problem was. There was no error message or anything. Just a big crash.