Bug #12560 Updated: 'parent' incorrectly refers to $this in certain cases
| From: | sniper@php.net | Date: | Mon, 22 Oct 2001 00:03:59 +0000 |
| Subject: | Bug #12560 Updated: 'parent' incorrectly refers to $this in certain cases | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-68662@lists.php.net to get a copy of this message | ||
ID: 12560
Updated by: sniper
Reported By: nick@macaw.demon.co.uk
Old Status: Open
Status: Closed
Bug Type: Class/Object related
Operating System: Solaris 2.7
PHP Version: 4.0.6
New Comment:
Works for me just fine with PHP 4.1.0RC1
Previous Comments:
------------------------------------------------------------------------
[2001-08-03 13:51:21] nick@macaw.demon.co.uk
This bug occurred with Solaris 2.7 and a regular build of php as a standalone app. I haven't
tested on Linux yet.
If the base class of a few levels of inheritance is in an included or required file, then
'parent' may be incorrectly setup. Calls via 'parent' will actually call $this,
and then give incorrect and most likely disastrous behaviour.
The following example will quickly crash due to stack overflow from infinite recursion, whereas
inlining the base class 'X' rather than including it will work as expected.
Incidentally, instantiating a B rather than a C will work correctly in both cases.
File X.php:
<?php
class X
{
function X() { }
}
?>
File crashme.php:
<?php
// Commenting out include and uncommenting class X
// below will work, whilst including X will crash
include_once 'X.php';
/*
class X
{
function X() { }
}
*/
class A extends X
{
function A() { $this->X(); }
function crash_me() { }
}
class B extends A
{
function B() { $this->A(); }
function crash_me() { parent::crash_me(); }
}
class C extends B
{
function C() { $this->B(); }
}
$r = new C();
$r->crash_me();
?>
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=12560&edit=1