Req #67935 [Com]: define() constants with unallowed characters
| From: | 1nflktd at gmail dot com | Date: | Thu, 04 Sep 2014 20:19:58 +0000 |
| Subject: | Req #67935 [Com]: define() constants with unallowed characters | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187423@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67935&edit=1
ID: 67935
Comment by: 1nflktd at gmail dot com
Reported by: 1nflktd at gmail dot com
Summary: define() constants with unallowed characters
Status: Not a bug
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: *
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
That's my point exactly.
In http://php.net/manual/en/language.constants.php
says:
"A valid constant name starts with a letter or underscore, followed by any number of letters,
numbers, or underscores."
Ok, that's fine.
But if you write whatever you want in define(), and access it with constant(), it works fine ? Is
this ok, then ? So why not let it very clear in the docs about this behavior ?
Previous Comments:
------------------------------------------------------------------------
[2014-08-30 09:52:30] nikic@php.net
You can still access these constants through the
constant() function, if you like.
------------------------------------------------------------------------
[2014-08-30 01:48:28] 1nflktd at gmail dot com
Description:
------------
Defining constants with invalid characters (e.g. leading numbers) are allowed, define() returns
true, checking the constant with defined() also returns true,
but when you try to use it you have a parse error.
Test script:
---------------
var_dump ( define ("0000X" , 1) );
var_dump ( defined ("0000X") );
echo 0000X;
http://sandbox.onlinephpfunctions.com/code/a7e955c09fbcc9e17a51ea56a75c70f8f60ab7e7
Expected result:
----------------
var_dump ( define ("0000X" , 1) ); // false, throwing an notice or a warning
var_dump ( defined ("0000X") ); // false
echo 0000X; // Parse error
Actual result:
--------------
var_dump ( define ("0000X" , 1) ); // true
var_dump ( defined ("0000X") ); // true
echo 0000X; // Parse error
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67935&edit=1