php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74183 preg_last_error not returning error code after error
Submitted: 2017-02-28 17:46 UTC Modified: 2018-02-14 16:24 UTC
Votes:3
Avg. Score:3.7 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:3 (100.0%)
From: velazcomtz dot miguel at gmail dot com Assigned: cmb (profile)
Status: Closed Package: *Regular Expressions
PHP Version: 5.6.30 OS: Ubuntu
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: velazcomtz dot miguel at gmail dot com
New email:
PHP Version: OS:

 

 [2017-02-28 17:46 UTC] velazcomtz dot miguel at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.preg-last-error
---
There are cases where preg_match returns false and preg_last_error returns 0 but, when you check the error.log file there is an error:

PHP message: PHP Warning:  preg_match(): Compilation failed: regular expression is too large at offset 128

Just as a reminder: this bug was detected and fixed previously here: https://bugs.php.net/bug.php?id=52732&edit=2

Test script:
---------------
$sRegex = "/([A-Z]|[a-z]|[0-9]| |Ñ|ñ|!|"|%|&|'|´|-|:|;|>|=|<|@|_|,|\{|\}|`|~|á|é|í|ó|ú|Á|É|Í|Ó|Ú|ü|Ü){1,300}/";
$sTest = "Hello world";

var_dump(preg_match($sRegex, $sTextoPrueba)); // returns false
var_dump(preg_last_error()); // returns 0


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-28 17:48 UTC] velazcomtz dot miguel at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.preg-last-error
---
There are cases where preg_match returns false and preg_last_error returns 0 but, when you check the error.log file there is an error:

PHP message: PHP Warning:  preg_match(): Compilation failed: regular expression is too large at offset 128

Just as a reminder: this bug was detected and fixed previously here: https://bugs.php.net/bug.php?id=52732&edit=2

Test script:
---------------
$sRegex = "/([A-Z]|[a-z]|[0-9]| |Ñ|ñ|!|"|%|&|'|´|-|:|;|>|=|<|@|_|,|\{|\}|`|~|á|é|í|ó|ú|Á|É|Í|Ó|Ú|ü|Ü){1,300}/";
$sTest = "Hello world";

var_dump(preg_match($sRegex, $sTest)); // returns false
var_dump(preg_last_error()); // returns 0
 [2017-03-10 18:29 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2017-03-10 18:29 UTC] cmb@php.net
Confirmed: <https://3v4l.org/1eUf6>.

Seems there is

    PCRE_G(error_code) = PHP_PCRE_INTERNAL_ERROR;

missing around <https://github.com/php/php-src/blob/PHP-7.1.2/ext/pcre/php_pcre.c#L499>.
 [2017-11-21 11:44 UTC] andrew dot nester dot dev at gmail dot com
Thanks for reporting this issue! I've just added PR fixing this.
 [2017-11-21 19:28 UTC] ab@php.net
Automatic comment on behalf of andrew.nester.dev@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8fdef981ef940dfc2f1b21cfa3f227150472ad2d
Log: Fixed #75539 and #74183 - preg_last_error not returning error code after error
 [2018-02-14 16:24 UTC] cmb@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: cmb
 [2018-02-14 16:24 UTC] cmb@php.net
This issue has already been fixed (see comment above).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 08:01:28 2024 UTC