php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45748 preg_replace_callback : named subpattern not implemented
Submitted: 2008-08-07 23:34 UTC Modified: 2008-08-08 09:44 UTC
From: xxorax at gmail dot com Assigned:
Status: Closed Package: PCRE related
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID:
 [2008-08-07 23:34 UTC] xxorax at gmail dot com
Description:
------------
named subpattern is not passed with their names in the array of the callback function in preg_replace_callback.

this is the same bug of Bug #37911 (1 year) but it is not fixed !

thanks

Reproduce code:
---------------
$regex = '#(?P<int>\d+):(?P<text>\w+)#';

$data = <<<TEST
zedz:fzef
234:zefrfr
13232erf:erfrfe
345345:rgrtgtr
TEST;

function func ($m) {
	print_r($m);
	return "match";
}
echo $data."\n";
echo preg_replace_callback($regex, 'func', $data);

Expected result:
----------------
zedz:fzef
234:zefrfr
13232erf:erfrfe
345345:rgrtgtr
Array
(
    [0] => 234:zefrfr
    [int] => 234
    [text] => zefrfr
)
Array
(
    [0] => 345345:rgrtgtr
    [int] => 345345
    [text] => rgrtgtr
)
zedz:fzef
match
13232erf:erfrfe
match

Actual result:
--------------
zedz:fzef
234:zefrfr
13232erf:erfrfe
345345:rgrtgtr
Array
(
    [0] => 234:zefrfr
    [1] => 234
    [2] => zefrfr
)
Array
(
    [0] => 345345:rgrtgtr
    [1] => 345345
    [2] => rgrtgtr
)
zedz:fzef
match
13232erf:erfrfe
match

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-08 09:44 UTC] lbarnaud@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.

This had been fixed in 5.3 but not in older branches. This is now
fixed in 5.2 and will be available in future 5.2 snapshots.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 04:01:55 2014 UTC