Bug #73947 [Opn->Nab]: preg_match() behavior change
| From: | requinix@php.net | Date: | Mon, 16 Jan 2017 13:56:51 +0000 |
| Subject: | Bug #73947 [Opn->Nab]: preg_match() behavior change | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-206671@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73947&edit=1
ID: 73947
Updated by: requinix@php.net
Reported by: thekid@php.net
Summary: preg_match() behavior change
-Status: Open
+Status: Not a bug
Type: Bug
Package: PCRE related
Operating System: Windows
PHP Version: master-Git-2017-01-16 (snap)
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
This is a deliberate change introduced by fixing bug #61780.
https://github.com/php/php-src/commit/ee6aaee83a4a72791b0750c495538dfcf6ce7ce8
https://github.com/php/php-src/pull/1303
It is mentioned in UPGRADING.
https://github.com/php/php-src/commit/c832ab4de68485df67d09ebb8d2bf55b658c5e30
Previous Comments:
------------------------------------------------------------------------
[2017-01-16 13:48:15] thekid@php.net
Description:
------------
Optional patterns, if not matched, seem to return NULL instead of empty strings in certain
situations.
Test script:
---------------
var_dump([preg_match("!([a-z]+)://([^@]+@)?([a-z]+)!", "http://domain", $matches), $matches]);
Expected result:
----------------
array(2) {
[0]=>
int(1)
[1]=>
array(4) {
[0]=>
string(13) "http://domain"
[1]=>
string(4) "http"
[2]=>
string(0) ""
[3]=>
string(6) "domain"
}
}
Actual result:
--------------
array(2) {
[0]=>
int(1)
[1]=>
array(4) {
[0]=>
string(13) "http://domain"
[1]=>
string(4) "http"
[2]=>
NULL
[3]=>
string(6) "domain"
}
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73947&edit=1