#38350 [Opn->Bgs]: regexpr string causes error at runtime.

From: Date: Sat, 05 Aug 2006 18:19:20 +0000
Subject: #38350 [Opn->Bgs]: regexpr string causes error at runtime.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-100402@lists.php.net to get a copy of this message
ID: 38350 Updated by: tony2001@php.net Reported By: syacko at nayaco dot com -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: RHEL 4 update 3 Linux PHP Version: 5.1.4 New Comment: 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\$/"; Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#100402) next »