php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73947 preg_match() behavior change
Submitted: 2017-01-16 13:48 UTC Modified: 2017-01-16 13:56 UTC
From: thekid@php.net Assigned: cmb (profile)
Status: Not a bug Package: PCRE related
PHP Version: master-Git-2017-01-16 (snap) OS: Windows
Private report: No CVE-ID: None
 [2017-01-16 13:48 UTC] 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"
  }
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-16 13:56 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Nov 27 20:03:20 2021 UTC