From: z_rules55 at hotmail dot com
Operating system: WinXP
PHP version: 5.1.6
PHP Bug Type: Variables related
Bug description: PHP allows invalid names for constants and variables
Description:
------------
The PHP manual states that:
A valid variable name starts with a letter or
underscore, followed by any number of letters,
numbers, or underscores.
And that constants must follow the same naming rules as variables.
However, PHP allows me to define variables and constants with an invalid
character like a hyphen or a dollar sign, as well as starting with a
number. Those are the only three invalid names I tested; I assume others
could also be used.
Reproduce code:
---------------
<?php
define('my$definition', 'value');
define('my-definition', 'value');
define('2mydefinition', 'value');
$var = '2morrow$is-another-day';
$$var = 'this should be invalid';
echo constant('my$definition')."\n";
echo constant('my-definition')."\n";
echo constant('2mydefinition')."\n";
echo $GLOBALS['2morrow$is-another-day']."\n";
echo "\n";
//echo my$definition."\n";
echo my-definition."\n";
//echo 2mydefinition."\n";
//echo $2morrow$is-another-day."\n";
?>
Expected result:
----------------
Some kind of error upon defining the constant or variable with the invalid
name.
Actual result:
--------------
PHP happily accepts the define() with the invalid name, as well as the
assignment to the variable variable with the invalid name. Using
constant() and $GLOBALS to read the value of the invalid constant and
variable work fine. Echoing the value of my-definition gives the usual
warning of:
Notice: Use of undefined constant my - assumed 'my' in
C:\path\to\script.php on line 14
Notice: Use of undefined constant definition -
assumed 'definition' in C:\path\to\script.php
on line 14
Only when you try to access the invalid constant or variable directly does
PHP throw parse errors.
--
Edit bug report at http://bugs.php.net/?id=39150&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=39150&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=39150&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=39150&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39150&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=39150&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39150&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39150&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39150&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39150&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39150&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=39150&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=39150&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39150&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39150&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39150&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39150&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39150&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39150&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39150&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39150&r=mysqlcfg