[RFC][DISCUSSION] Add preg_replace_callback_array function

php.internals

David Dai

11 years ago
Hi internals, The RFC to add a user-land function for an easy-to-use and reliable preg_replace_callback_array() in PHP is up for discussion: https://wiki.php.net/rfc/preg_replace_callback_array This proposes adding one function: `preg_replace_callback_array()` that is the better way to Implement when there are multiple patterns need to replace. I would love to hear your feedback! :) Any objections? — Best, Wei Dai

Laruence

11 years ago
Hey: On Mon, Mar 16, 2015 at 9:40 AM, Wei Dai <zxcvdavid@gmail.com> wrote:
> Hi internals, > > The RFC to add a user-land function for an easy-to-use and reliable > preg_replace_callback_array() in PHP is up for discussion: > https://wiki.php.net/rfc/preg_replace_callback_array > > This proposes adding one function: `preg_replace_callback_array()` that > is the better way to Implement when there are multiple patterns need to > replace. > > I would love to hear your feedback! :) > Any objections?
I have no objections on this, since I proposed similar thing before.. I think this is a good addition after we removed /e if you objections raise in couple days, I will merge this. thanks
> > > — > Best, > Wei Dai >
-- Xinchen Hui @Laruence http://www.laruence.com/

Peter Cowburn

11 years ago
On 16 March 2015 at 01:40, Wei Dai <zxcvdavid@gmail.com> wrote:
> Hi internals, > > The RFC to add a user-land function for an easy-to-use and reliable > preg_replace_callback_array() in PHP is up for discussion: > https://wiki.php.net/rfc/preg_replace_callback_array > > This proposes adding one function: `preg_replace_callback_array()` that > is the better way to Implement when there are multiple patterns need to > replace. > > I would love to hear your feedback! :) >
Could you add a paragraph or two explaining the reasons for choosing this particular proposal? Some examples of what I would like to read: - why we can't do preg_replace_callback($array_of_regexes, $array_of_callbacks, $subject) - why not preg_replace_callback($array_of_regex_to_callback_pairs, $subject) - why not pass the regex used to the callback, as per Laruence's earlier RFC And give a few links to historical discussions in the same sort of area? E.g Laruence's RFC: https://wiki.php.net/rfc/second_arg_to_preg_callback and its discussion thread (http://php.markmail.org/thread/qwiyq5o2vwlbdczq).

Laruence

11 years ago
Hey: On Mon, Mar 16, 2015 at 5:45 PM, Peter Cowburn <petercowburn@gmail.com> wrote:
> On 16 March 2015 at 01:40, Wei Dai <zxcvdavid@gmail.com> wrote: > >> Hi internals, >> >> The RFC to add a user-land function for an easy-to-use and reliable >> preg_replace_callback_array() in PHP is up for discussion: >> https://wiki.php.net/rfc/preg_replace_callback_array >> >> This proposes adding one function: `preg_replace_callback_array()` that >> is the better way to Implement when there are multiple patterns need to >> replace. >> >> I would love to hear your feedback! :) >> > > Could you add a paragraph or two explaining the reasons for choosing this > particular proposal? > Some examples of what I would like to read: > - why we can't do preg_replace_callback($array_of_regexes, > $array_of_callbacks, $subject)
array() also could be a valid callback.. (array("clasname", "methodname")).
> - why not preg_replace_callback($array_of_regex_to_callback_pairs, > $subject)
there are also $limit, $count argument could be used.
> - why not pass the regex used to the callback, as per Laruence's earlier > RFC
bc break..(change the callback's signature)
> > And give a few links to historical discussions in the same sort of area? > E.g Laruence's RFC: https://wiki.php.net/rfc/second_arg_to_preg_callback and > its discussion thread (http://php.markmail.org/thread/qwiyq5o2vwlbdczq). >
thanks
> > > >> Any objections? >> >> >> — >> Best, >> Wei Dai >> >>
-- Xinchen Hui @Laruence http://www.laruence.com/

Peter Cowburn

11 years ago
On 16 March 2015 at 14:59, Xinchen Hui <laruence@php.net> wrote:
> Hey: > > On Mon, Mar 16, 2015 at 5:45 PM, Peter Cowburn <petercowburn@gmail.com> > wrote: > > On 16 March 2015 at 01:40, Wei Dai <zxcvdavid@gmail.com> wrote: > > > >> Hi internals, > >> > >> The RFC to add a user-land function for an easy-to-use and reliable > >> preg_replace_callback_array() in PHP is up for discussion: > >> https://wiki.php.net/rfc/preg_replace_callback_array > >> > >> This proposes adding one function: `preg_replace_callback_array()` that > >> is the better way to Implement when there are multiple patterns need to > >> replace. > >> > >> I would love to hear your feedback! :) > >> > > > > Could you add a paragraph or two explaining the reasons for choosing this > > particular proposal? > > Some examples of what I would like to read: > > - why we can't do preg_replace_callback($array_of_regexes, > > $array_of_callbacks, $subject) > array() also could be a valid callback.. (array("clasname", "methodname")). > > - why not preg_replace_callback($array_of_regex_to_callback_pairs, > > $subject) > there are also $limit, $count argument could be used. > > - why not pass the regex used to the callback, as per Laruence's earlier > > RFC > bc break..(change the callback's signature) > > > > And give a few links to historical discussions in the same sort of area? > > E.g Laruence's RFC: https://wiki.php.net/rfc/second_arg_to_preg_callback > and > > its discussion thread (http://php.markmail.org/thread/qwiyq5o2vwlbdczq). > > > thanks >
In case my earlier message wasn't clear, I was asking for the RFC itself to be padded out with those sorts of details. The reason being, many (most) people won't be already familiar with the surrounding discussions that have happened previously, or the reasons for the potentially strange-seeming design choices made in this RFC.

Laruence

11 years ago
Hey: On Mon, Mar 16, 2015 at 11:32 PM, Peter Cowburn <petercowburn@gmail.com> wrote:
> On 16 March 2015 at 14:59, Xinchen Hui <laruence@php.net> wrote: > >> Hey: >> >> On Mon, Mar 16, 2015 at 5:45 PM, Peter Cowburn <petercowburn@gmail.com> >> wrote: >> > On 16 March 2015 at 01:40, Wei Dai <zxcvdavid@gmail.com> wrote: >> > >> >> Hi internals, >> >> >> >> The RFC to add a user-land function for an easy-to-use and reliable >> >> preg_replace_callback_array() in PHP is up for discussion: >> >> https://wiki.php.net/rfc/preg_replace_callback_array >> >> >> >> This proposes adding one function: `preg_replace_callback_array()` that >> >> is the better way to Implement when there are multiple patterns need to >> >> replace. >> >> >> >> I would love to hear your feedback! :) >> >> >> > >> > Could you add a paragraph or two explaining the reasons for choosing this >> > particular proposal? >> > Some examples of what I would like to read: >> > - why we can't do preg_replace_callback($array_of_regexes, >> > $array_of_callbacks, $subject) >> array() also could be a valid callback.. (array("clasname", "methodname")). >> > - why not preg_replace_callback($array_of_regex_to_callback_pairs, >> > $subject) >> there are also $limit, $count argument could be used. >> > - why not pass the regex used to the callback, as per Laruence's earlier >> > RFC >> bc break..(change the callback's signature) >> > >> > And give a few links to historical discussions in the same sort of area? >> > E.g Laruence's RFC: https://wiki.php.net/rfc/second_arg_to_preg_callback >> and >> > its discussion thread (http://php.markmail.org/thread/qwiyq5o2vwlbdczq). >> > >> thanks >> > > In case my earlier message wasn't clear, I was asking for the RFC itself to > be padded out with those sorts of details. The reason being, many (most) > people won't be already familiar with the surrounding discussions that have > happened previously, or the reasons for the potentially strange-seeming > design choices made in this RFC.
hmm, yeah, it's better to have these in the RFC. I just replied in case Wei Dai is not familar with these reasons thanks
> > >> > >> > >> > >> >> Any objections? >> >> >> >> >> >> — >> >> Best, >> >> Wei Dai >> >> >> >> >> >> >> >> -- >> Xinchen Hui >> @Laruence >> http://www.laruence.com/ >>
-- Xinchen Hui @Laruence http://www.laruence.com/

David Dai

11 years ago
Hi Peter: Sorry to reply late, because the GFW, I can’t access *.google.com at home.
> > > On 16 March 2015 at 14:59, Xinchen Hui <laruence@php.net (mailto:laruence@php.net)> wrote: > > Hey: > > > > On Mon, Mar 16, 2015 at 5:45 PM, Peter Cowburn <petercowburn@gmail.com (mailto:petercowburn@gmail.com)> wrote: > > > On 16 March 2015 at 01:40, Wei Dai <zxcvdavid@gmail.com (mailto:zxcvdavid@gmail.com)> wrote: > > > > > > > Hi internals, > > > > > > > > The RFC to add a user-land function for an easy-to-use and reliable > > > > preg_replace_callback_array() in PHP is up for discussion: > > > > https://wiki.php.net/rfc/preg_replace_callback_array > > > > > > > > This proposes adding one function: `preg_replace_callback_array()` that > > > > is the better way to Implement when there are multiple patterns need to > > > > replace. > > > > > > > > I would love to hear your feedback! :) > > > > > > Could you add a paragraph or two explaining the reasons for choosing this > > > particular proposal? > > > Some examples of what I would like to read: > > > - why we can't do preg_replace_callback($array_of_regexes, > > > $array_of_callbacks, $subject) > > > > array() also could be a valid callback.. (array("clasname", "methodname")). > > > - why not preg_replace_callback($array_of_regex_to_callback_pairs, > > > $subject) > > > > there are also $limit, $count argument could be used. > > > - why not pass the regex used to the callback, as per Laruence's earlier > > > RFC > > > > bc break..(change the callback's signature) > > > > > > And give a few links to historical discussions in the same sort of area? > > > E.g Laruence's RFC: https://wiki.php.net/rfc/second_arg_to_preg_callback and > > > its discussion thread (http://php.markmail.org/thread/qwiyq5o2vwlbdczq). > > > > thanks >
I accept, and I will be add these details in RFC.
> > In case my earlier message wasn't clear, I was asking for the RFC itself to be padded out with those sorts of details. The reason being, many (most) people won't be already familiar with the surrounding discussions that have happened previously, or the reasons for the potentially strange-seeming design choices made in this RFC.
Thanks for the suggestion. :)
> > > > > > > > > > > > > Any objections? > > > > > > > > > > > > — > > > > Best, > > > > Wei Dai > > > > > > > > > > > > > -- > > Xinchen Hui > > @Laruence > > http://www.laruence.com/ >
— Wei Dai

David Dai

11 years ago
Hi internals,
> Hi internals, > > The RFC to add a user-land function for an easy-to-use and reliable > preg_replace_callback_array() in PHP is up for discussion: > https://wiki.php.net/rfc/preg_replace_callback_array > > This proposes adding one function: `preg_replace_callback_array()` that > is the better way to Implement when there are multiple patterns need to > replace. > > I would love to hear your feedback! :) > Any objections?
I’ve sent this mail for four days, I don’t know if this RFC needs a vote. If you guys have no objections on this, please review the code and merge it, thanks.
> > > — > Best, > Wei Dai
— Wei Dai

Pierre Joye

11 years ago
On Fri, Mar 20, 2015 at 7:03 PM, Wei Dai <zxcvdavid@gmail.com> wrote:
> Hi internals, >> Hi internals, >> >> The RFC to add a user-land function for an easy-to-use and reliable >> preg_replace_callback_array() in PHP is up for discussion: >> https://wiki.php.net/rfc/preg_replace_callback_array >> >> This proposes adding one function: `preg_replace_callback_array()` that >> is the better way to Implement when there are multiple patterns need to >> replace. >> >> I would love to hear your feedback! :) >> Any objections? > > I’ve sent this mail for four days, I don’t know if this RFC needs a vote. > If you guys have no objections on this, please review the code and merge it, > thanks.
Nice job, i like the idea. I am not sure about a RFC or not. It somehow looks like a sane replacement for something we killed (with good reasons). Let see what the other think :)

Alain Williams

11 years ago
On Fri, Mar 20, 2015 at 10:46:58PM +1100, Pierre Joye wrote:
> On Fri, Mar 20, 2015 at 7:03 PM, Wei Dai <zxcvdavid@gmail.com> wrote: > > Hi internals, > >> Hi internals, > >> > >> The RFC to add a user-land function for an easy-to-use and reliable > >> preg_replace_callback_array() in PHP is up for discussion: > >> https://wiki.php.net/rfc/preg_replace_callback_array > >> > >> This proposes adding one function: `preg_replace_callback_array()` that > >> is the better way to Implement when there are multiple patterns need to > >> replace. > >> > >> I would love to hear your feedback! :) > >> Any objections? > > > > I’ve sent this mail for four days, I don’t know if this RFC needs a vote. > > If you guys have no objections on this, please review the code and merge it, > > thanks. > > Nice job, i like the idea. > > I am not sure about a RFC or not. It somehow looks like a sane > replacement for something we killed (with good reasons). > > Let see what the other think :)
I used s/something/code/ge in a perl script that I wrote a few days ago. Very useful. It would have been a lot more work to do it another way. So: +1 to the ability to do this, regardless of what mechanism is eventually chosen.
-- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include <std_disclaimer.h>

Laruence

11 years ago
Hey: On Fri, Mar 20, 2015 at 7:53 PM, Alain Williams <addw@phcomp.co.uk> wrote:
> On Fri, Mar 20, 2015 at 10:46:58PM +1100, Pierre Joye wrote: >> On Fri, Mar 20, 2015 at 7:03 PM, Wei Dai <zxcvdavid@gmail.com> wrote: >> > Hi internals, >> >> Hi internals, >> >> >> >> The RFC to add a user-land function for an easy-to-use and reliable >> >> preg_replace_callback_array() in PHP is up for discussion: >> >> https://wiki.php.net/rfc/preg_replace_callback_array >> >> >> >> This proposes adding one function: `preg_replace_callback_array()` that >> >> is the better way to Implement when there are multiple patterns need to >> >> replace. >> >> >> >> I would love to hear your feedback! :) >> >> Any objections? >> > >> > I’ve sent this mail for four days, I don’t know if this RFC needs a vote. >> > If you guys have no objections on this, please review the code and merge it, >> > thanks. >> >> Nice job, i like the idea. >> >> I am not sure about a RFC or not. It somehow looks like a sane >> replacement for something we killed (with good reasons). >> >> Let see what the other think :) > > I used s/something/code/ge in a perl script that I wrote a few days ago. Very > useful. It would have been a lot more work to do it another way. > > So: +1 to the ability to do this, regardless of what mechanism is eventually chosen.
I also +1 for this. if there is no objections raises, I am going to merge it tomorrow.. thanks
> > -- > Alain Williams > Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. > +44 (0) 787 668 0256 http://www.phcomp.co.uk/ > Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php > #include <std_disclaimer.h> > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php
-- Xinchen Hui @Laruence http://www.laruence.com/

Laruence

11 years ago
Hey: On Fri, Mar 20, 2015 at 9:14 PM, Xinchen Hui <laruence@php.net> wrote:
> Hey: > > On Fri, Mar 20, 2015 at 7:53 PM, Alain Williams <addw@phcomp.co.uk> wrote: >> On Fri, Mar 20, 2015 at 10:46:58PM +1100, Pierre Joye wrote: >>> On Fri, Mar 20, 2015 at 7:03 PM, Wei Dai <zxcvdavid@gmail.com> wrote: >>> > Hi internals, >>> >> Hi internals, >>> >> >>> >> The RFC to add a user-land function for an easy-to-use and reliable >>> >> preg_replace_callback_array() in PHP is up for discussion: >>> >> https://wiki.php.net/rfc/preg_replace_callback_array >>> >> >>> >> This proposes adding one function: `preg_replace_callback_array()` that >>> >> is the better way to Implement when there are multiple patterns need to >>> >> replace. >>> >> >>> >> I would love to hear your feedback! :) >>> >> Any objections? >>> > >>> > I’ve sent this mail for four days, I don’t know if this RFC needs a vote. >>> > If you guys have no objections on this, please review the code and merge it, >>> > thanks. >>> >>> Nice job, i like the idea. >>> >>> I am not sure about a RFC or not. It somehow looks like a sane >>> replacement for something we killed (with good reasons). >>> >>> Let see what the other think :) >> >> I used s/something/code/ge in a perl script that I wrote a few days ago. Very >> useful. It would have been a lot more work to do it another way. >> >> So: +1 to the ability to do this, regardless of what mechanism is eventually chosen. > > I also +1 for this. > > if there is no objections raises, I am going to merge it tomorrow..
merged thanks
> > thanks >> >> -- >> Alain Williams >> Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. >> +44 (0) 787 668 0256 http://www.phcomp.co.uk/ >> Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php >> #include <std_disclaimer.h> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > Xinchen Hui > @Laruence > http://www.laruence.com/
-- Xinchen Hui @Laruence http://www.laruence.com/

Marc Bennewitz

11 years ago
I also had a question! Didn't you noticed it? Am 20.03.2015 um 16:49 schrieb Marc Bennewitz:
> Why not simply allow the callback to be an array, too?
Marc Am 21.03.2015 um 09:14 schrieb Xinchen Hui:

Sebastian B.-Hagensen

11 years ago
Hi, 2015-03-21 19:30 GMT+01:00 Marc Bennewitz <dev@mabe.berlin>:
> I also had a question! Didn't you noticed it? > > Am 20.03.2015 um 16:49 schrieb Marc Bennewitz: >> >> Why not simply allow the callback to be an array, too?
Because arrays are valid callbacks. [$object, 'cb'] would call the the 'cb' method on the $object.

Marc Bennewitz

11 years ago
Am 20.03.2015 um 09:03 schrieb Wei Dai:
> Hi internals, >> Hi internals, >> >> The RFC to add a user-land function for an easy-to-use and reliable >> preg_replace_callback_array() in PHP is up for discussion: >> https://wiki.php.net/rfc/preg_replace_callback_array >> >> This proposes adding one function: `preg_replace_callback_array()` that >> is the better way to Implement when there are multiple patterns need to >> replace. >> >> I would love to hear your feedback! :) >> Any objections?
Why not simply allow the callback to be an array, too?