Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67292 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72432 invoked from network); 4 May 2013 12:49:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 May 2013 12:49:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.45 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.219.45 mail-oa0-f45.google.com Received: from [209.85.219.45] ([209.85.219.45:44472] helo=mail-oa0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/5A-26044-AE305815 for ; Sat, 04 May 2013 08:49:46 -0400 Received: by mail-oa0-f45.google.com with SMTP id o17so2415453oag.18 for ; Sat, 04 May 2013 05:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=bBko9mjT3ErCPlERlNhI0RhozGyyClJXUz/ofunvpsE=; b=jvoiXWa2jsvOJxogPYFw7e8cf3Ixd2W89AmVi5/2h6aCXYWvaf3IGWKBbgasvQ422L axjv+fq1jZQYgPBFk0RrbxEdfmJFpLbu5BF9ZUAyPdRx2lpty0AN3eXtm0Rs+DaiGiOe OTjqlsg+pNubIlqgiTJQo3sS3dguxnKMBAXVKh4NP8PmB/InFLevp4zm+r+Ju2bY7T1C bQUbznG3zfpRWERm0lP4TvFj8tFizJTxpJZDjQGzNb8meZjrjATLsm1w3S8nFNiDZhC0 JPMD3n7EOoRD03YqnS7nDvkX9eLeLSwPkbnKkrwjWLWWrh9kPlGvXetlj/rtq06lxqeq +G9w== MIME-Version: 1.0 X-Received: by 10.60.56.168 with SMTP id b8mr3832230oeq.5.1367671782871; Sat, 04 May 2013 05:49:42 -0700 (PDT) Received: by 10.182.49.136 with HTTP; Sat, 4 May 2013 05:49:42 -0700 (PDT) In-Reply-To: References: Date: Sat, 4 May 2013 14:49:42 +0200 Message-ID: To: Laruence Cc: PHP Internals Content-Type: multipart/alternative; boundary=089e0149ca96c9981a04dbe3e685 Subject: Re: [PHP-DEV] Re: [PROPOSAL]Add second to callback of preg_replace_callback From: nikita.ppv@gmail.com (Nikita Popov) --089e0149ca96c9981a04dbe3e685 Content-Type: text/plain; charset=ISO-8859-1 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, 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 --089e0149ca96c9981a04dbe3e685--