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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: thekid@php.net
New email:
PHP Version: OS:

 

 [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-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 09:01:28 2024 UTC