Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67199 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31166 invoked from network); 29 Apr 2013 16:46:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2013 16:46:30 -0000 Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.46 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.215.46 mail-la0-f46.google.com Received: from [209.85.215.46] ([209.85.215.46:65500] helo=mail-la0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/A1-23191-3E3AE715 for ; Mon, 29 Apr 2013 12:46:28 -0400 Received: by mail-la0-f46.google.com with SMTP id fs13so2985330lab.33 for ; Mon, 29 Apr 2013 09:46:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:sender:from:date:x-google-sender-auth :message-id:subject:to:content-type; bh=KZBnPQ0tCNyJpqYIZaILMxEfNBat1g4X07vWdA13PtI=; b=G/uzrrcJQxXo2UKy1Whsar/pt3cu16LhtvsNXQ3zo8ffX77BW9iWzIc146UREw4ZbS Sde/hoz8Vc7My3S/xMRVAFFtQFNvnNFqqRPrvvA/mUiLYvWYIdbl8ERfLGpuCXgzdU9t Eg2t0Rt3hq4SJsyNodzebpCYk3sfVA8zgx83CaZcxbRXOWyuTOrB45Rmcp/8CXm4bbKr cWO5orRoMifTaMBVwjT1ErjMlEgBa0ZOA3nYCwtEniWCNfIAVcIky7L48FNeexc7MeKF 2LrFUtr5wfb27grm9H1OKQcFwtwt6henOIh63xYBvDKU9/FnPG/fMiZtbyWzZRPIXGxF RnqQ== X-Received: by 10.112.5.196 with SMTP id u4mr21131266lbu.78.1367253984022; Mon, 29 Apr 2013 09:46:24 -0700 (PDT) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.114.97.231 with HTTP; Mon, 29 Apr 2013 09:46:03 -0700 (PDT) Date: Tue, 30 Apr 2013 00:46:03 +0800 X-Google-Sender-Auth: tEeFdhFTGZTeVZvX1jJTiyZ9XKw Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary=14dae94ed819093ded04db82a050 Subject: [PROPOSAL]Add second to callback of preg_replace_callback From: laruence@php.net (Laruence) --14dae94ed819093ded04db82a050 Content-Type: text/plain; charset=UTF-8 Hey: there comes a FR: https://bugs.php.net/bug.php?id=64730 the main idea is, in 5.5 we remove support of 'e' modifier. then comes a problem, the old codes(a real use case see https://github.com/php/php-src/blob/PHP-5.4/Zend/zend_vm_gen.php#L390): preg_replace(array( "/pattern1(.*)/", "/pattern2(.*)/" ), array( "/replace1/e", "/replace2/e" ) ..), can not be easier convert to the "callback" style. then I have to change it to something very ugly like(a real use case see: https://github.com/php/php-src/blob/PHP-5.5/Zend/zend_vm_gen.php#L390): function callback($subject) { if (!strncmp($subject, "pattern1", 8)) { //function for pattern 1 } else if(!strncmp($subject, "pattern2", 8)) { //function for pattern 2 } else ..... } so I propose to add a second argument to callback(aim to php-5.5.1), which is the matched regex string self. then I can simplify the previous codes to: function callback ($subject, $regex) { $replace_funcs = array( "/pattern1(.*)" => function ($subect) { //function for parttern 1; }, "/pattern2(.*)" => function($sbuect) { //function for pattern 2; } ); $replace_funcs[$regex]($subject); } what do you think(of course, the second argument can also easily change to be the regex idx in the regex array)? patch is here: https://bugs.php.net/patch-display.php?bug_id=64730&patch=sencode_argument.patch&revision=latest -- Laruence Xinchen Hui http://www.laruence.com/ --14dae94ed819093ded04db82a050--