#41141 [Opn->Bgs]: Class as static variable
| From: | johannes@php.net | Date: | Fri, 20 Apr 2007 05:30:59 +0000 |
| Subject: | #41141 [Opn->Bgs]: Class as static variable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-111713@lists.php.net to get a copy of this message | ||
ID: 41141
Updated by: johannes@php.net
Reported By: flopin at webgarden dot cz
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
Operating System: any
PHP Version: 6CVS-2007-04-19 (snap)
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
.
Previous Comments:
------------------------------------------------------------------------
[2007-04-19 23:57:17] flopin at webgarden dot cz
Description:
------------
It is not possible to create and assign new class instance to static
variable in declaration of another class.
Reproduce code:
---------------
class A {
public $dummy='AAA';
}
class B {
static $foo=new A();
}
Expected result:
----------------
The variable B::$foo should contain an instance of class A, instead the
parser returns error "Parse error: syntax error, unexpected T_NEW in
/var/www/php6/test.php6 on line 6".
It is possible to hack the problem with code like this:
class A {
public $dummy='AAA';
}
class B {
static $foo=null;
static function prepare() {
self::$foo = new A();
}
}
B::prepare();
but since i need to use this construct in my program widely, the code
gets very crappy, buggy and unreadable
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41141&edit=1