Bug #70283 [Opn]: Manual does not mention new reserved keywords (string/etc)

From: Date: Tue, 08 Dec 2015 22:11:29 +0000
Subject: Bug #70283 [Opn]: Manual does not mention new reserved keywords (string/etc)
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-12917@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: yohgaki@php.net Reported by: bugs dot php dot net at majkl578 dot cz -Summary: Misleading error message when attempting to instantiate a reserved class name +Summary: Manual does not mention new reserved keywords (string/etc) Status: Open Type: Bug -Package: Scripting Engine problem +Package: Documentation problem Operating System: Linux PHP Version: 7.0Git-2015-08-17 (Git) Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [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

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