|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12560 'parent' incorrectly refers to $this in certain cases
Submitted: 2001-08-03 13:51 UTC Modified: 2001-10-21 20:03 UTC
From: nick at macaw dot demon dot co dot uk Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.0.6 OS: Solaris 2.7
Private report: No CVE-ID: None
 [2001-08-03 13:51 UTC] nick at macaw dot demon dot co dot 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:


class X
      function X() { }


File crashme.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();



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-21 20:03 UTC]
Works for me just fine with PHP 4.1.0RC1

 [2002-10-16 07:25 UTC] public at macfreek dot nl
I also encountered this bug using PHP 4.0.6 on Linux. I was not able to replicate it using simpler code, then the complex code I was using now. It should be noted that I am using standalone PHP.

I tried to replicate the bug on PHP 4.1.0 buy my complex code failed there for other reasons; I will post an update if I can replicate it there or using a short code fragment.
 [2002-10-16 07:31 UTC] public at macfreek dot nl
Addition: the bug indeed does exist in standalone PHP 4.0.6 on Linux, and not on standalone PHP 4.1.1 on Linux.

(I earlier encountered the bug in a complex set of code I was using, but couldn't replicate it with extracting simpler code. Until I of course just copied the above: it did immediately give me a segementation fault on 4.0.6)
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 18:01:30 2024 UTC