php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52928 Segfault using parent::_construct
Submitted: 2010-09-27 01:14 UTC Modified: 2010-11-30 12:35 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: M8R-nheyum at mailinator dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.3 OS: CentOS release 4.8
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: M8R-nheyum at mailinator dot com
New email:
PHP Version: OS:

 

 [2010-09-27 01:14 UTC] M8R-nheyum at mailinator dot com
Description:
------------
When calling parent::__construct using call_user_func_array, a segfault occurs. 
Script to reproduce attached below.

This worked in 5.2.14.

Expected: instantiation of class
Actual: segfault

Notes: Only occurs with multiple nesting levels. A single level doesn't cause 
this.

Test script:
---------------
<?

class baseA{
        function foo(){
                return 'bar';
        }

        function __construct(){
                foo();
        }
}
class baseB extends baseA  {
    function __construct(){
        $args = func_get_args();
        call_user_func_array(array($this, 'parent::__construct'), $args);
    }

        }


class demo extends baseB{
    function __construct(){
        $args = func_get_args();
        call_user_func_array(array($this, 'parent::__construct'), $args);
    }
}

$z = new demo('d');
?>

Expected result:
----------------
instantiation of class

Actual result:
--------------
segfault. 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-27 02:26 UTC] felipe@php.net
This is causing an infinite recursion, but works fine on 5.2.15-dev.
 [2010-09-27 04:24 UTC] cataphract@php.net
Stack overflow on Windows, trunk.
 [2010-11-30 12:17 UTC] weishj at qq dot com
If the parent class is not defined, it also end up with segmentation fault.
<?php
class base  {
    function __construct(){
        call_user_func(array($this,'parent::__construct'));
    }
}
class demo extends base{
    function __construct(){
        parent::__construct();
    }
}
$z = new demo;
?>
 [2010-11-30 12:35 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-11-30 12:35 UTC] johannes@php.net
This is an endless recursion Endless recursion gives a stack overflow which causes a segfault.

call_user_func_array(array($this, 'parent::__construct'), $args);

Takes $this's scope so get_class($this) and then the parent's constructor.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 20 18:00:03 2025 UTC