On Sat, May 4, 2013 at 2:39 PM, Laruence <larue...@php.net> wrote:

> Hey:
>    Sorry for the delay,  the new patch, which make the second argument the
> regex array keys is attached.
>
>
>
> https://bugs.php.net/patch-display.php?bug_id=64730&patch=second_arg_rege_key.patch&revision=latest
>
>    with this patch,  preg_replace_callback will call user callback with two
> arguments, the first one is the same,  the second is the regex key if the
> regex is an array or NULL if the regex is a string.
>
>    then we can do something like:
>
>     $code = preg_replace_callback(
> array(
> "foo" => "/some very complex regex/",
> "bar" => "/another one/",
> ...
> ),
> function($matches, $idx)  {
>  switch ($idx) {
>   case 'foo'
>     ...
>   case 'bar':
>     ...
>  }
> },
> $code);
>
>
>   if no objections,  I will commit this patch after 5.5. 0 final release..
>
>   thanks
>

I object. If this were using the preg_replace_callback(Array, Array,
String) syntax [which is not practically possible due to ambiguity], I
would agree that this is a nice feature which makes the function consistent
with preg_replace and str_replace. But this implementation with some weird
additional identifier that you need to switch over makes absolutely no
sense to me and only complicated the API. Better to just use a loop for
this.

One thing that might be nicer API wise but without ambiguity is an
preg_replace_callback(['regex' => callback], $string) overload. Though
personally I'm not really a fan of doing overloads with completely
different argument types.

Nikita

Reply via email to