ID: 30702
Updated by: [EMAIL PROTECTED]
Reported By: douglass_davis at earthlink dot net
Status: Open
-Bug Type: Documentation problem
+Bug Type: Zend Engine 2 problem
Operating System: Windows XP
PHP Version: 5.0.2
New Comment:
I think this was supposed to work..
Previous Comments:
------------------------------------------------------------------------
[2004-11-06 15:30:23] douglass_davis at earthlink dot net
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 this bug report at http://bugs.php.net/?id=30702&edit=1