Req #75133 [Opn->Dup]: When preg_replace fails, please write to error_log
| From: | cmb@php.net | Date: | Tue, 29 Aug 2017 13:54:50 +0000 |
| Subject: | Req #75133 [Opn->Dup]: When preg_replace fails, please write to error_log | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210868@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75133&edit=1
ID: 75133
Updated by: cmb@php.net
Reported by: php at richardneill dot org
Summary: When preg_replace fails, please write to error_log
-Status: Open
+Status: Duplicate
Type: Feature/Change Request
Package: PCRE related
Operating System: Linux
PHP Version: 7.0.22
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Duplicate of bug #51103.
Previous Comments:
------------------------------------------------------------------------
[2017-08-28 20:38:12] spam2 at rhsoft dot net
there is no reason to spit into the error log just because you don't properly check return
values where you can calk error_log() at your own
proper production servers have E_ALL enabled and if something spits into my logs or enforce using @
would lead to a bug report to fix that broken behavior
------------------------------------------------------------------------
[2017-08-28 18:33:45] php at richardneill dot org
Description:
------------
It's very rare that preg_replace() fails (i.e. returns null). But when it happens, it's
really unexpected, and therefore particularly hard to debug. All the normal tools show nothing
helpful.
Can I request that whenever preg_replace (and preg_replace_callback) return a null, that
preg_last_error() is printed to the error_log, at least at E_NOTICE?
Test script:
---------------
It may be helpful to give an example. This code generates a
PREG_JIT_STACKLIMIT_ERROR, with only ~ 5kB of data in $contents
$contents =
preg_replace_callback
('/^\s*\%LOOP_(\d+|(ITR)(\d))\s*\n((((?!%LOOP_ITR).)*\n)*)\s*\%END_LOOP\s*\n/mU',
'repeat_n_times', $contents);
Expected result:
----------------
It shouldn't be possible to write a 1-line regexp which hits resource-limits on one screenful
of text. But if we do, it would be really helpful if there were some error message in the log files.
Actual result:
--------------
PHP Notice: preg_replace experienced a PREG_JIT_STACKLIMIT_ERROR in (filename) on (line_number)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75133&edit=1