From:             
Operating system: 2.6.34-gentoo-r6 GNU/Linux
PHP version:      5.3SVN-2011-11-03 (snap)
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:can't instantiate using class constant

Description:
------------
I wanted to write something like this inside a method.
DEFAULT_CLASS is a string containing a name of an existing class.
The problem is that there is no way to instantiate an object using a class

constant by using "new self::CLASS_CONSTANT";

This will generate a syntax error.

I know that the workaround is to store the value of the class constant into
a 
variable, but couldn't this be improved somehow?

Test script:
---------------
<?php
class default_class {
    function do_nothing() {
    }
}

class TheParent {

const DEFAULT_CLASS="default_class";

    public function init() {
        $c=new self::DEFAULT_CLASS;
    }

}

Expected result:
----------------
I would expect to have an object instantiated with the class stored in the

DEFAULT_CLASS constant.

Actual result:
--------------
Produces a syntax error:

syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in 
/some_path/test.php on line 14


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

Reply via email to