ID: 35123 User updated by: joe at popcast dot com Reported By: joe at popcast dot com -Status: Feedback +Status: Open Bug Type: Reproducible crash Operating System: linux, XP, Mac PHP Version: 5.0.5 New Comment:
I forgot to post the work around .... Too many hours programming today. If you redeclare $test in the subclasses (see commented out code), you get the expected results of "ABC". The var scope in classes A, B, and C should all be public or protected (the example code incorrectly has them mixed with public in A and protected in B and C; this is just a typo and not a factor in the test). When reproducing the crash, setting $test in class A to either public or protected yields the same results. Previous Comments: ------------------------------------------------------------------------ [2005-11-06 09:52:17] [EMAIL PROTECTED] Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip ------------------------------------------------------------------------ [2005-11-06 09:42:14] joe at popcast dot com Description: ------------ Using PHP from the standard Windows installer and running under Apache, the following code both produces unexpected output and crashes PHP. The code is a simple OOP variable test. A similar bug was posted (http://bugs.php.net/bug.php?id=26930) but did not crash PHP. To reproduce the crash, uncomment the test method in class B or C and seg fault away. The bug is reproducible on every OS I've tested, including Linux and Mac with standard PHP installs running under Apache. Reproduce code: --------------- class A { protected static $instance; public $test = "A"; public function getInstance() { if (! self::$instance) self::$instance = new A; return self::$instance; } public function test() { echo $this->test; } } class B extends A { protected static $instance; //protected $test = "B"; public function getInstance() { if (! self::$instance) self::$instance = new B; self::$instance->test = "B"; return self::$instance; } /* public function test() { echo $this->test(); } */ } class C extends A { protected static $instance; //protected $test = "C"; public function getInstance() { if (! self::$instance) self::$instance = new C; self::$instance->test = "C"; return self::$instance; } /* public function test() { echo $this->test(); } */ } $a = new A; $a->test(); echo "\n----------<br>\n"; $b = new B; $a->test(); $b->test(); echo "\n----------<br>\n"; $c = new C; $a->test(); $b->test(); $c->test(); echo "\n----------<br>\n"; Expected result: ---------------- A ---------- AB ---------- ABC ---------- Actual result: -------------- A ---------- AA ---------- AAA ---------- ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=35123&edit=1