From:             sweiss at stylesight dot com
Operating system: Debian
PHP version:      5.3.0
PHP Bug Type:     Class/Object related
Bug description:  Cannot define class constant with constant value

Description:
------------
In the PHP documentation it states:

"It is possible to define constant values on a per-class basis 
remaining the same and unchangeable. Constants differ from normal 
variables in that you don't use the $ symbol to declare or use them.

"The value must be a constant expression, not (for example) a 
variable, a class member, result of a mathematical operation or a 
function call."

This is however not entirely the case.

If you define a constant within a class based on another constant, it 
will not work, despite the fact that it is a constant value.

In the given example, X_CONST . "Y" is a constant composed of two 
other constants - no variables, class members, math expressions, or 
function calls.

And, in fact, for normal, non-class constants, this is totally 
possible:

define("Y_CONST", X_CONST . "Y");

is totally valid.

At the very least the documentation should be updated to reflect 
simply that a class constant may only be defined as a simple scalar 
value, and not just any constant expression.

Reproduce code:
---------------
define("X_CONST", "Const");
 
class TestClass {
        
        const Y_CONST = X_CONST . "Y";

        function test() {
            return self::Y_CONST;
        }
}

$a = new TestClass();
var_dump($a->test());

Expected result:
----------------
(string) "ConstY"

Actual result:
--------------
Parse error: syntax error, unexpected '.', expecting ',' or ';' in line 
5

-- 
Edit bug report at http://bugs.php.net/?id=49431&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=49431&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=49431&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=49431&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=49431&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49431&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=49431&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=49431&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=49431&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=49431&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=49431&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=49431&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=49431&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=49431&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=49431&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49431&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49431&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=49431&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=49431&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=49431&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=49431&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=49431&r=mysqlcfg

Reply via email to