php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61321 Crash on __call + __invoke magic
Submitted: 2012-03-07 22:07 UTC Modified: 2012-03-08 13:34 UTC
From: lol at nrzw dot net Assigned: laruence (profile)
Status: Closed Package: Reproducible crash
PHP Version: 5.3.10 OS: Linux (CentOS, Deb)
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lol at nrzw dot net
New email:
PHP Version: OS:

 

 [2012-03-07 22:07 UTC] lol at nrzw dot net
Description:
------------
Using PHP versions 5.3.3 up to 5.3.10:

A 'container' has many 'bags', but few methods. Each 'bag' has its own methods that are callable through it's magic __invoke method. No methods collide with the properties of the 'container', so one would expect that:

bag_container->bagone('e', array('Some Text'))

Would trigger bag_container's __call (since no method 'bagone' exists in 'bag_container'), which would further trigger the __invoke method in class 'bag'.

Unfortunately, it just creates a segfault =|

I see that there is a related bug (https://bugs.php.net/bug.php?id=53195&edit=2), but since the bug has not been updated and this one produces different behavior (segfault), I felt that I should resubmit. Apologies if that's wrong.

Test script:
---------------
class bag {
        public function e($something) {
                echo $something;
        }
        public function __invoke() {
                return call_user_func_array(array($this, $method), $args);
        }
}
class bag_container {
        public $bagone;
        public function __construct() {
                $this->bagone = new bag();
        }
        public function __call($method, array $args = array()) {
            return call_user_func_array(array($this, $method), $args);
        }
}
$c = new bag_container();
$c->bagone('e', array('wtf'));

Expected result:
----------------
One would expect 'wtf' to be echo'd.

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-08 02:53 UTC] laruence@php.net
do you mean like this: 
<?php
class bag {
    public function e($something) {
        print_r($something);
    }
    public function __invoke($args) {
        return call_user_func_array(array($this, array_shift($args)), $args);
    }
}
class bag_container {
    public $bagone;
    public function __construct() {
        $this->bagone = new bag();
    }
    public function __call($method, array $args = array()) {
        $this->bagone->__invoke($args);
    }
}
$c = new bag_container();
$c->bagone('e', array('wtf'));
 [2012-03-08 02:53 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2012-03-08 02:58 UTC] lol at nrzw dot net
-Status: Feedback +Status: Closed
 [2012-03-08 02:58 UTC] lol at nrzw dot net
@laruence@php.net

I suppose I did =) I don't see how I missed that (I chopped down my code as I am obviously not working with bags).

I don't see why this would cause a segfault instead of issuing a failure/warning notice, but that works =) Thank you!
 [2012-03-08 08:23 UTC] cataphract@php.net
-Status: Closed +Status: Re-Opened
 [2012-03-08 08:23 UTC] cataphract@php.net
If it segfaults, there's still a bug. Please don't close it.
 [2012-03-08 13:30 UTC] laruence@php.net
@cataphract it's a knew segfault, that is the call stack exceeded. so I think it's 
okey to close it.
 [2012-03-08 13:34 UTC] laruence@php.net
-Status: Re-Opened +Status: Closed -Assigned To: +Assigned To: laruence
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 04 00:00:02 2025 UTC