Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-06 Thread Stas Malyshev
Hi! > Here is another example from a real case (Horde_Date) Looks like the case of doing it wrong. In most cases it doesn't even need regexp, in others, generic regexp with post-parsing would probably be more efficient as this seems to do 20+ passes through the string. -- Stanislav Malyshev, S

Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-06 Thread Remi Collet
Le 04/05/2013 14:39, Laruence a écrit : >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. Here is another example from a real case (Horde_

Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-05 Thread Etienne Kneuss
On Sat, May 4, 2013 at 4:31 PM, Laruence wrote: > I made a RFC for this: > https://wiki.php.net/rfc/second_arg_to_preg_callback > > Note that giving meaning to an extra argument in existing callbacks constitutes a small BC break in at least two cases: 1) function myhandyfunction($v, $arg = 42)

Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-04 Thread Rasmus Lerdorf
On 05/04/2013 08:28 AM, Laruence wrote: > and inefficent not always means performance only, in this case , you > need to define various functions for different regexs if you use loop style. > > and do you prefer array_walk or foreach when you try to iteraterly > process an array? I certainly

Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-04 Thread Laruence
I made a RFC for this: https://wiki.php.net/rfc/second_arg_to_preg_callback thanks On Sat, May 4, 2013 at 10:28 PM, Laruence wrote: > > > > On Sat, May 4, 2013 at 9:46 PM, Anthony Ferrara wrote: > >> Laruence, >> >> > foreach ($replacements as $regex => $callback) { >> > > $str = preg_re

Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-04 Thread Laruence
On Sat, May 4, 2013 at 9:46 PM, Anthony Ferrara wrote: > Laruence, > > > foreach ($replacements as $regex => $callback) { > > > $str = preg_replace_callback($regex, $callback, $str); > > > } > > > > > > > So if there are 10 regex in the array, you will got 10 DO_FCALL. 10 > times > > argumen

Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-04 Thread Anthony Ferrara
Laruence, > foreach ($replacements as $regex => $callback) { > > $str = preg_replace_callback($regex, $callback, $str); > > } > > > > So if there are 10 regex in the array, you will got 10 DO_FCALL. 10 times > arguments accept, 10 times etc... > > and AS I already said: IT is inefficient. I

Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-04 Thread Laruence
On Sat, May 4, 2013 at 8:58 PM, Nikita Popov wrote: > On Sat, May 4, 2013 at 2:52 PM, Laruence wrote: > >> >> >> >> On Sat, May 4, 2013 at 8:49 PM, Nikita Popov wrote: >> >>> On Sat, May 4, 2013 at 2:39 PM, Laruence wrote: >>> Hey: Sorry for the delay, the new patch, which make th

Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-04 Thread Nikita Popov
On Sat, May 4, 2013 at 2:52 PM, Laruence wrote: > > > > On Sat, May 4, 2013 at 8:49 PM, Nikita Popov wrote: > >> On Sat, May 4, 2013 at 2:39 PM, Laruence wrote: >> >>> Hey: >>>Sorry for the delay, the new patch, which make the second argument >>> the >>> regex array keys is attached. >>> >

Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-04 Thread Laruence
On Sat, May 4, 2013 at 8:49 PM, Nikita Popov wrote: > On Sat, May 4, 2013 at 2:39 PM, Laruence 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=sec

Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-04 Thread Laruence
On Sat, May 4, 2013 at 8:49 PM, Nikita Popov wrote: > On Sat, May 4, 2013 at 2:39 PM, Laruence 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=sec

Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-04 Thread Nikita Popov
On Sat, May 4, 2013 at 2:39 PM, Laruence 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,

[PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback

2013-05-04 Thread Laruence
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,