|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-10-19 11:31 UTC] nicolas dot grekas+php at gmail dot com
Description:
------------
preg_replace_callback_array's $limit argument is used independently for all items in the $patterns array.
I'm not sure this is the behavior that it should have. It makes it possible for example to has $count > $limit. This is counter intuitive.
Test script:
---------------
echo preg_replace_callback_array(
array(
'/[^a]/' => function () {return 'a';},
'/a/' => function () {return 'd';},
),
'abca',
3,
$count
);
echo $count;
Expected result:
----------------
daaa3
Actual result:
--------------
ddda5
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 03:00:01 2025 UTC |
This behavior is consistent with preg_replace_callback(): echo preg_replace_callback( array('/[^a]/', '/a/'), function () {return 'a';}, 'abca', 3, $count ), "\n"; echo $count, "\n"; // 5 And for that matter also with preg_replace(): echo preg_replace( array('/[^a]/', '/a/'), 'a', 'abca', 3, $count ), "\n"; echo $count, "\n"; // 5 Regardless of how this ought to have worked originally, I don't think it makes sense to change this at this point. The limit is for each replacement, rather than for all replacements together.