#35123 [Opn->Bgs]: here's how to seg fault php everytime by doing simple OOP
| From: | johannes@php.net | Date: | Sun, 06 Nov 2005 08:58:00 +0000 |
| Subject: | #35123 [Opn->Bgs]: here's how to seg fault php everytime by doing simple OOP | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-87673@lists.php.net to get a copy of this message | ||
ID: 35123
Updated by: johannes@php.net
Reported By: joe at popcast dot com
-Status: Open
+Status: Bogus
Bug Type: Reproducible crash
Operating System: linux, XP, Mac
PHP Version: 5.0.5
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
I should read the code: You're calling $this->test()
inside your test method so you get endless recursion ->
segfault.
Previous Comments:
------------------------------------------------------------------------
[2005-11-06 09:54:06] joe at popcast dot com
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.
------------------------------------------------------------------------
[2005-11-06 09:52:17] johannes@php.net
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