Bug #70283 [Opn]: Misleading error message when attempting to instantiate a reserved class name
| From: | cmb@php.net | Date: | Thu, 17 Dec 2015 08:43:33 +0000 |
| Subject: | Bug #70283 [Opn]: Misleading error message when attempting to instantiate a reserved class name | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-197963@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70283&edit=1
ID: 70283
Updated by: cmb@php.net
Reported by: bugs dot php dot net at majkl578 dot cz
-Summary: Manual does not mention new reserved keywords
(string/etc)
+Summary: Misleading error message when attempting to
instantiate a reserved class name
Status: Open
Type: Bug
-Package: Documentation problem
+Package: Scripting Engine problem
Operating System: Linux
PHP Version: 7.0Git-2015-08-17 (Git)
Block user comment: N
Private report: N
New Comment:
yohgaki wrote:
> http://php.net/manual/en/reserved.keywords.php
> does not mention new "string"/etc keywords. I'll make this
> report as Documentation problem.
Type names (
string etc.) are not proper keywords, but rather
reserved names and already listed as such[1]. Therefore this issue
is not a documentation issue.
jonathan dot massuchetti at gmail dot com wrote:
> A) stick to that behavior and trigger a parse error
Please note the difference between proper keywords and reserved
words. The former will trigger parse errord when used in
(syntactically) invalid contexts, but, IMHO rightly so, not the
latter. For instance, it's possible to use string as name of a
user defined function[2].
[1] <http://php.net/manual/en/reserved.other-reserved-words.php>
[2] <https://3v4l.org/IR9Hq>
Previous Comments:
------------------------------------------------------------------------
[2015-12-08 22:11:29] yohgaki@php.net
It seems ok to me raising E_ERROR for non defined classes and raising E_ERROR for non language
instruction keywords. (Strictly speaking, "string" class is not parse error, but soft
limitation)
http://php.net/manual/en/reserved.keywords.php
does not mention new "string"/etc keywords. I'll make this report as Documentation
problem.
[yohgaki@dev PHP-7.0]$ ./php-bin
<?php
class string{}
?>
Fatal error: Cannot use 'string' as class name as it is reserved in - on line 2
[yohgaki@dev PHP-7.0]$ ./php-bin
<?php
class int{}
?>
Fatal error: Cannot use 'int' as class name as it is reserved in - on line 2
[yohgaki@dev PHP-7.0]$ php -v
PHP 5.6.15 (cli) (built: Oct 29 2015 15:24:09)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
[yohgaki@dev PHP-7.0]$ php
<?php
class while{}
?>
PHP Parse error: syntax error, unexpected 'while' (T_WHILE), expecting identifier
(T_STRING) in - on line 2
------------------------------------------------------------------------
[2015-09-16 13:42:26] jonathan dot massuchetti at gmail dot com
PHP 5 behavior when trying to instantiate a reserved word, such as "new return", "new
class" or so, is a parse error :
Parse Error: syntax error, unexpected 'class' (T_CLASS)
So IMHO we should :
A) stick to that behavior and trigger a parse error
B) create a new error message for all reserved word usage attempt.
I vote A.
------------------------------------------------------------------------
[2015-08-17 16:55:03] bugs dot php dot net at majkl578 dot cz
Description:
------------
When trying to instantiate a reserved class name (e.g. string/int/float/resource), the message
should probably mention that the name is reserved, not that "class ____ not found".
Test script:
---------------
<?php
new string;
Expected result:
----------------
Somethig like:
Fatal error: Uncaught Error: Could not instantiate 'string', the name is reserved
Actual result:
--------------
Fatal error: Uncaught Error: Class 'string' not found
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70283&edit=1