php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67935 define() constants with unallowed characters
Submitted: 2014-08-30 01:48 UTC Modified: 2014-08-30 09:52 UTC
From: 1nflktd at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS: *
Private report: No CVE-ID: None
 [2014-08-30 01:48 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-30 09:52 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2014-08-30 09:52 UTC] nikic@php.net
You can still access these constants through the `constant()` function, if you like.
 [2014-09-04 20:19 UTC] 1nflktd at gmail dot com
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 ?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 03:02:51 2024 UTC