Bug #61321 [Csd->ReO]: Crash on __call + __invoke magic
| From: | cataphract@php.net | Date: | Thu, 08 Mar 2012 08:23:38 +0000 |
| Subject: | Bug #61321 [Csd->ReO]: Crash on __call + __invoke magic | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-168263@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61321&edit=1
ID: 61321
Updated by: cataphract@php.net
Reported by: lol at nrzw dot net
Summary: Crash on __call + __invoke magic
-Status: Closed
+Status: Re-Opened
Type: Bug
Package: Reproducible crash
Operating System: Linux (CentOS, Deb)
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
If it segfaults, there's still a bug. Please don't close it.
Previous Comments:
------------------------------------------------------------------------
[2012-03-08 02:58:30] 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 02:53:54] 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-07 22:07:51] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61321&edit=1