Bug #17277 Updated: strstr matches any variable surrounded by underscores

From: Date: Thu, 16 May 2002 21:31:23 +0000
Subject: Bug #17277 Updated: strstr matches any variable surrounded by underscores
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-7875@lists.php.net to get a copy of this message
ID: 17277 Updated by: derick@php.net Reported By: svemir@baltok.com Status: Bogus Bug Type: Strings related Operating System: Linux PHP Version: 4.2.1 New Comment: You're missing something indeed, _$needle_ is equivalent with "." . ${"needle_"} as underscores can be part of a variablename. As $needle_ is empty, the needle evaluates to "_", which is in "Moo _bar_" Not a bug > bogus. Derick Previous Comments: ------------------------------------------------------------------------ [2002-05-16 17:15:55] robert.cummings@webmotion.com _$ doesn't have anysignificance, but that trailing _ does, since it will try to match $needle_ as the variable name and that will be empty. ------------------------------------------------------------------------ [2002-05-16 17:10:47] svemir@baltok.com This script: <?php $needle = "foo"; echo "1: "; echo strstr("Moo _bar_", "_$needle_"); echo "<br>2: "; echo strstr("Moo _bar_", "_{$needle}_"); echo "<br>3: "; echo strstr("Moo _foo_", "_{$needle}_"); echo "<br>4: "; echo strstr("Moo !bar!", "!$needle!"); ?> Gives this output: 1: _bar_ 2: 3: _foo_ 4: Obviously, the line 1 is the problem. If both "haystack" and "needle" have the strings surrounded by underscores - the strings are matched even if they are actually different. This happens only if the "needle" has a variable between the underscores, and the variable is not surrounded by { and }. Prehaps I am missing something and the combination of "_$" is supposed to mean something, but i did not see it in the documentation. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17277&edit=1

« previous php.bugs (#7875) next »