php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31474 calling of the parent class method leads to recursion and segmentation fault
Submitted: 2005-01-10 17:23 UTC Modified: 2005-01-10 23:32 UTC
From: public at grik dot net Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.3 OS: linux
Private report: No CVE-ID: None
 [2005-01-10 17:23 UTC] public at grik dot net
Description:
------------
When I moved my classes hierarchy code from the PHP 4 to the PHP 5 and renamed costructors from the class names to "__construct", I faced a segmentation fault.

The constructor calls the parent's constructor. 
Parent's constructor calls another method, overloaded in the child's class.
That overloaded method from the child's class calls the constructor that calls the parent's constructor again.
But instead of the endless loop I get the segfault.

Reproduce code:
---------------
class A{
    function a1(){
        echo ' class a ';
    }
    function a2(){
        $this->a1();
    }
}
class B extends A {
    function a1(){
        $this->a2();
    }
    function __construct(){
        parent::a2();
    }
}
$a= new B();

Expected result:
----------------
Really, I would like to see the output of " class a " string,
cause it's not convenient to rewrite all occurences of
$this->method() to self::method in the base classes.
But I understand there is a new paradigm of "final" methods now and I will use it.

I would like to see the endless loop until script execution time expires:
B::a1() calls A::a2() and vice versa

Actual result:
--------------
Segmentation fault

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-10 21:08 UTC] jed@php.net
:: and -> are not equivalent operators, please read the manual. This is not a bug.
 [2005-01-10 21:12 UTC] derick@php.net
And for the record, you're nesting many levels of function calls, which exhaust the stack. That's why you get a segfault - the only case where it is acceptable in PHP.
 [2005-01-10 21:23 UTC] public at grik dot net
I do not claim the :: and -> are thre same.
The bug is the segfault.
Could you please be more careful?
 [2005-01-10 21:25 UTC] public at grik dot net
>you're nesting many levels of function calls 
exactly

>which exhaust the stack. 
why don't I get the "stack overflow" error?
or any error at all?

>That's why you get a segfault - the only case where it is acceptable in PHP.
I just think the blank page is not the best way to reflect errors :-)
 [2005-01-10 23:32 UTC] derick@php.net
Because there is no way to see *when* we're about to overflow the stack, so we leave the handling for that to the operating system.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 05:01:33 2024 UTC