#30702 [Opn->Asn]: cannot initialize class variable from class constant
| From: | sniper@php.net | Date: | Mon, 07 Mar 2005 20:49:08 +0000 |
| Subject: | #30702 [Opn->Asn]: cannot initialize class variable from class constant | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-75059@lists.php.net to get a copy of this message | ||
ID: 30702
Updated by: sniper@php.net
Reported By: douglass_davis at earthlink dot net
-Status: Open
+Status: Assigned
Bug Type: Zend Engine 2 problem
-Operating System: Windows XP
+Operating System: *
-PHP Version: 5.0.2
+PHP Version: 5CVS-2005-03-07
-Assigned To:
+Assigned To: andi
New Comment:
Does not work with latest HEAD nor latest PHP_5_0
Previous Comments:
------------------------------------------------------------------------
[2005-02-16 12:14:34] php at kaiundina dot de
seems to be the same Problem occuring at a slightly different place:
Bug #31601
------------------------------------------------------------------------
[2004-11-17 20:54:39] nlopess@php.net
It doesn't work with latest PHP 5.1 here:
Fatal error: Cannot access self:: when no class scope is active in
C:\cygwin\home\Nuno\kk.php on line 21
------------------------------------------------------------------------
[2004-11-16 12:22:25] tony2001@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5-STABLE-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5.0-win32-latest.zip
Works fine here.
------------------------------------------------------------------------
[2004-11-11 17:25:04] nlopess@php.net
I think this was supposed to work..
------------------------------------------------------------------------
[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