php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37911 preg_replace_callback ignores named groups
Submitted: 2006-06-25 21:22 UTC Modified: 2007-10-07 11:52 UTC
Votes:6
Avg. Score:4.0 ± 1.2
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:0 (0.0%)
From: thomas dot kalka at gmail dot com Assigned: andrei (profile)
Status: Closed Package: PCRE related
PHP Version: 5.1.4 OS: xubuntu
Private report: No CVE-ID: None
 [2006-06-25 21:22 UTC] thomas dot kalka at gmail dot com
Description:
------------
unfortunately preg_replace_callback does not handle named groups


Reproduce code:
---------------
<?php

$a = "bla blub blah";

$regex = '|(?P<name>blub)|';

function callback($match) { var_dump($match); return '-'; }

preg_replace_callback($regex,'callback',$a);

$m = array(); preg_match($regex,$a,$m); var_dump($m);

?>

Expected result:
----------------
array(3) {
  [0]=>
  string(4) "blub"
  ["name"]=>
  string(4) "blub"
  [1]=>
  string(4) "blub"
}
array(3) {
  [0]=>
  string(4) "blub"
  ["name"]=>
  string(4) "blub"
  [1]=>
  string(4) "blub"
}


Actual result:
--------------
array(2) {
  [0]=>
  string(4) "blub"
  [1]=>
  string(4) "blub"
}
array(3) {
  [0]=>
  string(4) "blub"
  ["name"]=>
  string(4) "blub"
  [1]=>
  string(4) "blub"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-07 11:52 UTC] nlopess@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Nov 15 04:01:34 2019 UTC