Skip to content

Commit 907bf78

Browse files
alexdowadnikic
authored andcommitted
Remove XFAIL from tests for 'bug' 48770
Bug 48770 was opened due to conflicting expectations about the behavior of: call_user_func_array(array($this, 'parent::methodName'), array($arg1,$arg2)) The one reporting the 'bug' seemed to think that since the method name was prefixed with `parent::`, it should call the method in the superclass of the *class where this code appears*. However, `$this` might be an instance of a subclass. If so, then it is quite reasonable that `call_user_func_array` will call the method as defined in the superclass of *the receiver*. So the 'bug' is not really a bug. Therefore, there is no need for an XFAIL in the tests. They should just pass. Amend tests to reflect the actual expected behavior of `call_user_func_array`, not what the person who reported bug 48770 thought it should be. Closes GH-5386.
1 parent 7a185b5 commit 907bf78

File tree

3 files changed

+16
-42
lines changed

3 files changed

+16
-42
lines changed

Zend/tests/bug48770.phpt

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,34 @@
11
--TEST--
22
Bug #48770 (call_user_func_array() fails to call parent from inheriting class)
3-
--XFAIL--
4-
See Bug #48770
53
--FILE--
64
<?php
75

86
class A {
9-
public function func($str) {
10-
var_dump(__METHOD__ .': '. $str);
11-
}
12-
private function func2($str) {
13-
var_dump(__METHOD__ .': '. $str);
14-
}
15-
protected function func3($str) {
16-
var_dump(__METHOD__ .': '. $str);
17-
}
18-
private function func22($str) {
19-
var_dump(__METHOD__ .': '. $str);
7+
public function func($arg) {
8+
echo "A::func called\n";
209
}
2110
}
2211

2312
class B extends A {
24-
public function func($str) {
25-
static $avoid_crash = 0;
26-
27-
if ($avoid_crash++ == 1) {
28-
print "This method shouldn't be called when using parent::func!\n";
29-
return;
30-
}
31-
32-
call_user_func_array(array($this, 'parent::func'), array($str));
33-
}
34-
private function func2($str) {
35-
var_dump(__METHOD__ .': '. $str);
13+
public function func($arg) {
14+
echo "B::func called\n";
3615
}
37-
protected function func3($str) {
38-
var_dump(__METHOD__ .': '. $str);
16+
17+
public function callFuncInParent($arg) {
18+
call_user_func_array(array($this, 'parent::func'), array($arg));
3919
}
4020
}
4121

4222
class C extends B {
43-
public function func($str) {
23+
public function func($arg) {
24+
echo "C::func called\n";
4425
parent::func($str);
4526
}
4627
}
4728

4829
$c = new C;
49-
$c->func('This should work!');
30+
$c->callFuncInParent('Which function will be called??');
5031

5132
?>
5233
--EXPECT--
53-
string(26) "A::func: This should work!"
34+
B::func called

Zend/tests/bug48770_2.phpt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
Bug #48770 (call_user_func_array() fails to call parent from inheriting class)
3-
--XFAIL--
4-
See Bug #48770
53
--FILE--
64
<?php
75

@@ -56,7 +54,7 @@ $c->func('This should work!');
5654

5755
?>
5856
--EXPECT--
59-
string(27) "A::func2: This should work!"
60-
string(27) "A::func3: This should work!"
61-
call_user_func_array(): Argument #1 ($function) must be a valid callback, cannot access private method A::func22()
62-
call_user_func_array(): Argument #1 ($function) must be a valid callback, class 'A' does not have a method 'inexistent'
57+
string(27) "B::func2: This should work!"
58+
string(27) "B::func3: This should work!"
59+
call_user_func_array(): Argument #1 ($function) must be a valid callback, cannot access private method B::func22()
60+
call_user_func_array(): Argument #1 ($function) must be a valid callback, class 'B' does not have a method 'inexistent'

Zend/tests/bug48770_3.phpt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
Bug #48770 (call_user_func_array() fails to call parent from inheriting class)
3-
--XFAIL--
4-
See Bug #48770
53
--FILE--
64
<?php
75

@@ -15,9 +13,6 @@ class A {
1513
protected function func3($str) {
1614
var_dump(__METHOD__ .': '. $str);
1715
}
18-
private function func22($str) {
19-
var_dump(__METHOD__ .': '. $str);
20-
}
2116
}
2217

2318
class B extends A {
@@ -52,4 +47,4 @@ $c->func('This should work!');
5247
--EXPECT--
5348
string(27) "B::func2: This should work!"
5449
string(27) "B::func3: This should work!"
55-
call_user_func_array(): Argument #1 ($function) must be a valid callback, class 'B' does not have a method 'inexistent'
50+
call_user_func_array(): Argument #1 ($function) must be a valid callback, class 'C' does not have a method 'inexistent'

0 commit comments

Comments
 (0)