#38350 [Bgs->Opn]: regexpr string causes error at runtime.
| From: | syacko at nayaco dot com | Date: | Sat, 05 Aug 2006 18:25:08 +0000 |
| Subject: | #38350 [Bgs->Opn]: regexpr string causes error at runtime. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-100404@lists.php.net to get a copy of this message | ||
ID: 38350
User updated by: syacko at nayaco dot com
Reported By: syacko at nayaco dot com
-Status: Bogus
+Status: Open
Bug Type: Scripting Engine problem
Operating System: RHEL 4 update 3 Linux
PHP Version: 5.1.4
New Comment:
Ok, fair enough on the quoting. The question is why does the second
example work. The bug is that there is different behavior for the same
action. Either way the parsing engine should see the $ and generate an
error.
Previous Comments:
------------------------------------------------------------------------
[2006-08-05 18:19:18] tony2001@php.net
private $myFilter = "/^NC([a-zA-Z]+)\.php$/";
"$" in strings means start of the variable.
You have to quote it to make the engine to ignore it:
private $myFilter = "/^NC([a-zA-Z]+)\.php\$/";
------------------------------------------------------------------------
[2006-08-05 18:09:14] syacko at nayaco dot com
Description:
------------
In a class, using a private variable with a regular expression will
cause a parseing error. The same regular expression in a method
variable will not.
Error Message:
Parse error: syntax error, unexpected '"' in
/nayaco/apps/releasemanager/test.php on line 8
Reproduce code:
---------------
Code that does not work:
<?php
$x = new regClass();
$x->main();
$x = null;
exit;
class regClass
{
private $myFilter = "/^NC([a-zA-Z]+)\.php$/";
public function main()
{
echo $this->myFilter."\n";
echo preg_match($this->myFilter, "NCScott.php", $myMatches);
print_r($myMatches);
}
}
?>
Code that works:
<?php
$x = new regClass();
$x->main();
$x = null;
exit;
class regClass
{
public function main()
{
$myFilter = "/^NC([a-zA-Z]+)\.php$/";
echo $myFilter."\n";
echo preg_match($myFilter, "NCScott.php", $myMatches);
print_r($myMatches);
}
}
?>
Expected result:
----------------
Both sets of code should produce the same result:
/^NC([a-zA-Z]+)\.php$/
1Array
(
[0] => NCScott.php
[1] => Scott
)
Actual result:
--------------
Parse error: syntax error, unexpected '"' in
/nayaco/apps/releasemanager/test.php on line 8
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=38350&edit=1