Req #78537 [NEW]: Make it possible to handle E_COMPILE_WARNING in set_error_handler
| From: | tandre@php.net | Date: | Sat, 14 Sep 2019 17:03:08 +0000 |
| Subject: | Req #78537 [NEW]: Make it possible to handle E_COMPILE_WARNING in set_error_handler | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-222743@lists.php.net to get a copy of this message | ||
From: tandre
Operating system: All
PHP version: Irrelevant
Package: *General Issues
Bug Type: Feature/Change Request
Bug description:Make it possible to handle E_COMPILE_WARNING in set_error_handler
Description:
------------
https://www.php.net/set_error_handler
> The following error types cannot be handled with a user defined
function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING,
E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the
file where set_error_handler() is called.
This is inconvenient for the following reasons:
- Compile warnings unintuitively can't be reported using whatever
monitoring was set up in set_error_handler, and may go unnoticed because
of this.
- Static analyzers (etc.) don't have a way to fetch the full list of
E_COMPILE_WARNINGS if there was more than one warning. Warnings such as
invalid octal escapes can occur more than once.
This also seems like a distinction that may no longer be necessary.
- This was implemented in 2000 in
https://github.com/php/php-src/commit/b80b8381d4c#diff-b09edfedd835ebc4491e565c147190e7R559
. The php engine has had many improvements (class Error), and this
change may no longer be necessary
- PHP tokenization(Zend/zend_language_scanner.l) can emit both
E_COMPILE_WARNING (e.g. "Unterminated comment starting line %d") and
E_DEPRECATED ("The (real) cast is deprecated, use (float) instead"). The
latter can be handled by user error handlers.
I see that https://bugs.php.net/bug.php?id=52517
was reported for php
5.3, but I still think this should be revisited for the following
reasons.
- E_DEPRECATED and E_COMPILE_WARNING can both be emitted when
tokenizing
- We may want to reconsider emitting E_DEPRECATED in php 7.4 for curly
braces/real casts if php-src should truly never throw without evaluating
the include()d file. (a user error handler could throw)
- The improvements to the php engine since php 5.3 were significant and
may allow user error handlers to be safely called. (finally{}, class
Error, etc)
- I couldn't find any pre-existing discussion of this for php 7
Test script:
---------------
<?php
// The only warning using E_DEPRECATED was introduced in php 7.4
if (PHP_VERSION_ID < 70400) { throw new Error('Expected php 7.4+'); }
set_error_handler(function ($errno, $errstr) {
echo "In custom error handler: $errno $errstr\n";
});
// Warning: Unterminated comment starting line 1 in
/home/tyson/programming/php-src/test.php(6) : eval()'d code on line 1
// Evaluated 1
eval('echo "Evaluated 1\n";/** ');
// In custom error handler: 8192 Array and string offset access syntax
with curly braces is deprecated
// Evaluated 2
eval('echo "Evaluated 2\n";if (false) {$x{2} = 3;}');
Expected result:
----------------
The "Unterminated comment starting line 1" warning would be handled by
the custom error handler
Actual result:
--------------
The "Unterminated comment starting line 1" is printed to stderr and
cannot be handled
--
Edit bug report at https://bugs.php.net/bug.php?id=78537&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78537&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78537&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78537&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78537&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78537&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78537&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78537&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78537&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78537&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78537&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78537&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78537&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78537&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78537&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78537&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78537&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78537&r=mysqlcfg