[prev in list] [next in list] [prev in thread] [next in thread]
List: php-doc-bugs
Subject: [DOC-BUGS] Doc #64907 [Com]: classname regex seems invalid
From: "php at kingsquare dot nl" <php-bugs () lists ! php ! net>
Date: 2013-05-23 8:21:15
Message-ID: E1UfQlv-0005gv-Pd () sgrv2 ! php ! net
[Download RAW message or body]
Edit report at https://bugs.php.net/bug.php?id=64907&edit=1
ID: 64907
Comment by: php at kingsquare dot nl
Reported by: php at kingsquare dot nl
Summary: classname regex seems invalid
Status: Open
Type: Documentation Problem
Package: Documentation problem
Operating System: n/a
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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 ;)
Previous Comments:
------------------------------------------------------------------------
[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
--
PHP Documentation Bugs Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic