Doc #64907 [Opn->Nab]: classname regex seems invalid

From: Date: Thu, 23 May 2013 18:26:30 +0000
Subject: Doc #64907 [Opn->Nab]: classname regex seems invalid
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9875@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64907&edit=1 ID: 64907 Updated by: aharvey@php.net Reported by: php at kingsquare dot nl Summary: classname regex seems invalid -Status: Open +Status: Not a bug Type: Documentation Problem Package: Documentation problem Operating System: n/a PHP Version: Irrelevant Block user comment: N Private report: N New Comment: I think you've misunderstood the regex, as salathe suggested. In English, it allows letters, underscores, and bytes from 0x7f to 0xff inclusive as the first character, then the same plus digits as subsequent characters. That's correct, as http://codepad.viper-7.com/PYIXWa demonstrates. Previous Comments: ------------------------------------------------------------------------ [2013-05-23 08:21:15] php at kingsquare dot nl The regex just matches the first and rest characters. The point is that 'a2:' as a class is allowed according to the regex, but isnt by the php engine... The colon isnt allowed in a classname. Thus the regex isnt correct. (and should be something like ^[a-zA-Z_][a-zA-Z0-9_]* Thus allowing the following: class a class _a class a3 but disallowing class 3 class ~a class »× class a: Which imho are all weird anyway ;) ------------------------------------------------------------------------ [2013-05-23 07:58:34] salathe@php.net Your testing regular expression is not anchored to the end of the subject string. It is matching *only* the letter "a". Try again with a $ anchor. ------------------------------------------------------------------------ [2013-05-23 06:40:50] php at kingsquare dot nl Description: ------------ I've tried to use the given regex for testing of my classname (which is dynamically built from various sources) but it seems that the given regex allows characters which shouldnt be allowed. The page http://php.net/manual/en/language.oop5.basic.php gives the '^[a-zA- Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' regex. But this would allow not only strange characters like '»×' which might be intened but also 'a:' which ofcourse would fail from a parse error... Test script: --------------- <?php $controllerName = 'a:'; var_dump(preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $controllerName)); eval('class '.$controllerName.' {}'); exit; Expected result: ---------------- I'd expect the parse error, but also the not the valid pregmatch. thus: int 0 ( ! ) Parse error: syntax error, unexpected ':', expecting '{' in test.php(5) : eval()'d code on line 1 Actual result: -------------- int 1 ( ! ) Parse error: syntax error, unexpected ':', expecting '{' in test.php(5) : eval()'d code on line 1 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64907&edit=1

« previous php.doc.bugs (#9875) next »