Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:11960 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7964 invoked by uid 1010); 6 Aug 2004 06:21:18 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 7939 invoked from network); 6 Aug 2004 06:21:18 -0000 Received: from unknown (HELO cancan.ter.dk) (213.237.11.129) by pb1.pair.com with SMTP; 6 Aug 2004 06:21:18 -0000 Received: from [192.168.1.32] (workpenguin [192.168.1.32]) by cancan.ter.dk (Symaskine) with ESMTP id 40CCB8A4021 for ; Fri, 6 Aug 2004 08:21:12 +0200 (CEST) Date: Fri, 06 Aug 2004 08:21:16 +0200 To: internals@lists.php.net Message-ID: <20040806073350.FC1B.PHP@ter.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable X-Mailer: Becky! ver. 2.05.10 Subject: Behaviour of preg_replace with /e From: php@ter.dk (Peter Brodersen) Hi, I have read PHP bug #15050 and PHP bug #10666. Example at bottom of this mail. Andrei states in bug #10666: "The fact that it backslash-escapes single and double quotes in matches before substituting $1 is a feature, not a bug, otherwise you'd have a really hard time figuring out which quotes go where when using evaluation strings." I assume that the result of '$1' would be 'A \"little\" test and a \'little\' test' =2E. evaluating to: A \"little\" test and a 'little' test This approach to handle $1 (by adding slashes) is ugly and pretty much a hack in my opinion. Is there really no way at all to consider $1 as a "real" variable? After all, there is no pain in perl running stuff like: s/(.*)/"$1 [".length($1)." characters]"/e; =2E. where the string includes ' and " As it currently is, any function called in /e would always require a wrapper to run stripslashes() - which could also be destructive since only one of ' and " is escaped in the eval'ed string parsed on to a function. This currently render the otherwise powerful /e-feature pretty useless. At least, the behaviour ought to be mentioned under the /e-flag at pcre.pattern.modifiers in the manual? (actually, it seems that the whole adaption of pcre has been performed without much consideration - even though it has been more structured, there are still leftovers such as delimiters, which only made sense in the shorthand-form present in perl, but not in a structured function with several arguments - flags might also have been moved into an argument for itself... it's a pity since there are many benefits from preg_* opposed to ereg_* such as speed, flexibility, more powerful features, etc...) Quick example, for the curious: (PHP4.3.8, PHP5.0.0) Expected result: A "little" test and a 'little' test A "little" test and a 'little' test Actual result: A \"little\" test and a 'little' test A "little" test and a \'little\' test magic_quotes_runtime is disabled (and unimportant, so is magic_quotes_gpc). --=20 - Peter Brodersen (trying not to be too much of a party pooper :)