简体   繁体   中英

PHP internals - what error logging function to use?

I'm writing a PHP extension (although its starting to look a lot like a zend extension). There are instances where it needs to write to a logging interface.

I see that zend_error() is being used elsewhere however:

  • reading the source code on github I found zend_error declared in zend/zend.h but I couldn't find the corresponding definition of the function

  • looking at the contexts in which zend_error is used, I suspect that calls will be rerouted/diverted by set_error_handler

Normally, the logging will happen in MINIT and MSHUTDOWN (where presumably an error handler defined by a script cannot have any influence) but there may be times in between as well - and I'm looking for some consistency. Hence trying to understand how the mechanism works.

Is it safe to use zend_error() in MINIT/MSHUTDOWN?

How do I ensure that I am always calling the the default error handler?

Well, I found this in the PHP Wiki . I think this is old, but I imagine it still applies to Zend3:

Don't use zend_error

zend_error() should only be used inside the engine. Inside PHP extensions only PHP's error functions shoudl be used. Typically php_error_docref() is the best choice. php_error_docref() will extend the error message by extra information, like the current function name and properly escape output where needed. zend_error() is used by the Zend Engine due to PHP's modular architecture where the Zend Engine and TSRM should be compilable without other parts of PHP. The engine therefore can not use PHP level APIs. This limitation does not exist in extensions.

What this says to me is that zend_error was written for use in the engine and not designed as one of the tools for use in building extensions. For that reason, you are unlikely to find documentation covering the details you are asking about, and, even if it DOES work reliably for you, it may not continue to do so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM