From:             douglass_davis at earthlink dot net
Operating system: Windows XP
PHP version:      5.0.2
PHP Bug Type:     Compile Failure
Bug description:  cannot initialize class variable from class constant

Description:
------------
The manual says we can use constants in initializing class variables. 
However, this is not the case, as you cannot initialize variables to
constants that are defined in the same class.

When trying to compile it gives an error saying the class scope is not
active.  However, the constant is inside the class.

Also, it does not give the error where the class is defined, but when it
is instantiated.  So, perhaps it is an inlining error?

Maybe this is what's supposed to happen, if so, then the manual needs to
say that constants from the same class can't be used to initialize a var.

Reproduce code:
---------------
// This works:

class Constants
{
  const DEFAULT_SIZE=5;
}

class Square
{
  public $size=Constants::DEFAULT_SIZE;
}
$r= new Square();

// this doesn't

class Square2
{
  const DEFAULT_SIZE=5;
  public $size=self::DEFAULT_SIZE;
}

$r= new Square2();

Expected result:
----------------
I expect it to compile

Actual result:
--------------
PHP Fatal error:  Cannot access self:: when no class scope is active in
C:\src\test\consttest.php on line 23

Fatal error: Cannot access self:: when no class scope is active in
C:\src\test\consttest.php on line 23


-- 
Edit bug report at http://bugs.php.net/?id=30702&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=30702&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30702&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30702&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=30702&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=30702&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=30702&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=30702&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=30702&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=30702&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=30702&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=30702&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=30702&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=30702&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=30702&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=30702&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=30702&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=30702&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=30702&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=30702&r=mysqlcfg

Reply via email to