php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52579 define() accepts characters out of range
Submitted: 2010-08-10 21:51 UTC Modified: 2010-08-10 23:21 UTC
From: johnston dot joshua at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.3 OS: Any
Private report: No CVE-ID: None
 [2010-08-10 21:51 UTC] johnston dot joshua at gmail dot com
Description:
------------
Constants can be defined with invalid characters in the name. The documentation is correct but there seems to be no validation that matches the docs when the constant's name is assigned to zend_constant.name

According to the docs on Constants:

The name of a constant follows the same rules as any label in PHP. A valid constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thusly: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

Test script:
---------------
<?php

define('/', 'slash');

echo constant('/'); // works

echo /; // parse error as expected

?>

Expected result:
----------------
define() should throw an error stating that the constant name has invalid characters in it


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-10 23:21 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-08-10 23:21 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

A constant may contain any character. Use constant() to retrieve the value. Only the parser doesn't allow any name but that's independent.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Aug 04 20:00:02 2025 UTC