|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 00:00:02 2025 UTC |
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'));