Skip to content

Commit ee510ee

Browse files
committed
Deprecate partially supported callables
This deprecates all callables that are accepted by call_user_func($callable) but not by $callable(). In particular: "self::method" "parent::method" "static::method" ["self", "method"] ["parent", "method"] ["static", "method"] ["Foo", "Bar::method"] [new Foo, "Bar::method"] RFC: https://wiki.php.net/rfc/deprecate_partially_supported_callables Closes GH-7446.
1 parent 1afe89f commit ee510ee

27 files changed

+247
-30
lines changed

UPGRADING

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ PHP 8.2 UPGRADE NOTES
3535
4. Deprecated Functionality
3636
========================================
3737

38+
- Core:
39+
. Callables that are not accepted by the $callable() syntax (but are accepted
40+
by call_user_func) are deprecated. In particular:
41+
42+
"self::method"
43+
"parent::method"
44+
"static::method"
45+
["self", "method"]
46+
["parent", "method"]
47+
["static", "method"]
48+
["Foo", "Bar::method"]
49+
[new Foo, "Bar::method"]
50+
51+
This does not affect normal method callables like "A::method" or
52+
["A", "method"]. A deprecation notice is only emitted on call. Both
53+
is_callable() and the callable type will silently accept these callables
54+
until support for them is removed entirely.
55+
56+
RFC: https://wiki.php.net/rfc/deprecate_partially_supported_callables
57+
3858
========================================
3959
5. Changed Functions
4060
========================================

Zend/tests/bug37138.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ st::e ();
1414
st::e2 ();
1515
stch::g ();
1616
?>
17-
--EXPECT--
17+
--EXPECTF--
1818
EHLO
19+
20+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
1921
EHLO
22+
23+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
2024
EHLO

Zend/tests/bug41026.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ try_class::main ();
2020

2121
echo "Done\n";
2222
?>
23-
--EXPECT--
23+
--EXPECTF--
24+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
2425
Done
2526
CHECKPOINT

Zend/tests/bug45186.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ try {
3838
}
3939

4040
?>
41-
--EXPECT--
41+
--EXPECTF--
4242
__call:
4343
string(3) "ABC"
4444
__call:
@@ -47,8 +47,12 @@ __call:
4747
string(3) "xyz"
4848
__call:
4949
string(3) "www"
50+
51+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
5052
__call:
5153
string(1) "y"
54+
55+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
5256
__call:
5357
string(1) "y"
5458
ok

Zend/tests/bug45186_2.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ try {
3838
}
3939

4040
?>
41-
--EXPECT--
41+
--EXPECTF--
4242
__call:
4343
string(3) "ABC"
4444
__call:
@@ -47,8 +47,12 @@ __call:
4747
string(3) "xyz"
4848
__call:
4949
string(3) "www"
50+
51+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
5052
__call:
5153
string(1) "y"
54+
55+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
5256
__call:
5357
string(1) "y"
5458
ok

Zend/tests/bug48770.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ $c = new C;
3030
$c->callFuncInParent('Which function will be called??');
3131

3232
?>
33-
--EXPECT--
33+
--EXPECTF--
34+
Deprecated: Callables of the form ["C", "parent::func"] are deprecated in %s on line %d
3435
B::func called

Zend/tests/bug48770_2.phpt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ $c = new C;
5353
$c->func('This should work!');
5454

5555
?>
56-
--EXPECT--
56+
--EXPECTF--
57+
Deprecated: Callables of the form ["C", "parent::func2"] are deprecated in %s on line %d
5758
string(27) "B::func2: This should work!"
59+
60+
Deprecated: Callables of the form ["C", "parent::func3"] are deprecated in %s on line %d
5861
string(27) "B::func3: This should work!"
62+
63+
Deprecated: Callables of the form ["C", "parent::func22"] are deprecated in %s on line %d
5964
call_user_func_array(): Argument #1 ($callback) must be a valid callback, cannot access private method B::func22()
65+
66+
Deprecated: Callables of the form ["C", "parent::inexistent"] are deprecated in %s on line %d
6067
call_user_func_array(): Argument #1 ($callback) must be a valid callback, class B does not have a method "inexistent"

Zend/tests/bug48770_3.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ $c = new C;
4444
$c->func('This should work!');
4545

4646
?>
47-
--EXPECT--
47+
--EXPECTF--
48+
Deprecated: Callables of the form ["C", "self::func2"] are deprecated in %s on line %d
4849
string(27) "B::func2: This should work!"
50+
51+
Deprecated: Callables of the form ["C", "self::func3"] are deprecated in %s on line %d
4952
string(27) "B::func3: This should work!"
53+
54+
Deprecated: Callables of the form ["C", "self::inexistent"] are deprecated in %s on line %d
5055
call_user_func_array(): Argument #1 ($callback) must be a valid callback, class C does not have a method "inexistent"

Zend/tests/bug66719.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ call_user_func(array(B::class, 'parent::who'));
3434
C::test();
3535

3636
?>
37-
--EXPECT--
37+
--EXPECTF--
3838
string(1) "B"
3939
string(1) "A"
40+
41+
Deprecated: Callables of the form ["B", "parent::who"] are deprecated in %s on line %d
4042
string(1) "A"
4143
string(1) "B"
4244
string(1) "A"
45+
46+
Deprecated: Callables of the form ["B", "parent::who"] are deprecated in %s on line %d
4347
string(1) "A"

Zend/tests/bug78770.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ class Test {
1919

2020
?>
2121
===DONE===
22-
--EXPECT--
22+
--EXPECTF--
23+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
2324
===DONE===

Zend/tests/bug78898.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@ $b = new B;
3030
$b->x();
3131

3232
?>
33-
--EXPECT--
34-
aaa
33+
--EXPECTF--
34+
a
35+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
36+
a
37+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
38+
a
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
--TEST--
2+
Deprecation of self/parent/static in callables
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
public function foo() {}
8+
}
9+
class B extends A {
10+
public function test() {
11+
// Different callables using self/parent/static
12+
echo "Test different callables\n";
13+
call_user_func("self::foo");
14+
call_user_func("parent::foo");
15+
call_user_func("static::foo");
16+
call_user_func(["self", "foo"]);
17+
call_user_func(["parent", "foo"]);
18+
call_user_func(["static", "foo"]);
19+
call_user_func(["B", "self::foo"]);
20+
call_user_func(["B", "parent::foo"]);
21+
call_user_func(["B", "static::foo"]);
22+
call_user_func(["B", "A::foo"]);
23+
24+
// Also applies to other things performing calls
25+
echo "Test array_map()\n";
26+
array_map("self::foo", [1]);
27+
28+
echo "Test is_callable() -- should be silent\n";
29+
var_dump(is_callable("self::foo"));
30+
31+
echo "Test callable type hint -- should be silent\n";
32+
$this->callableTypeHint("self::foo");
33+
}
34+
35+
public function callableTypeHint(callable $c) {}
36+
}
37+
38+
$b = new B;
39+
$b->test();
40+
41+
?>
42+
--EXPECTF--
43+
Test different callables
44+
45+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
46+
47+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
48+
49+
Deprecated: Use of "static" in callables is deprecated in %s on line %d
50+
51+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
52+
53+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
54+
55+
Deprecated: Use of "static" in callables is deprecated in %s on line %d
56+
57+
Deprecated: Callables of the form ["B", "self::foo"] are deprecated in %s on line %d
58+
59+
Deprecated: Callables of the form ["B", "parent::foo"] are deprecated in %s on line %d
60+
61+
Deprecated: Callables of the form ["B", "static::foo"] are deprecated in %s on line %d
62+
63+
Deprecated: Callables of the form ["B", "A::foo"] are deprecated in %s on line %d
64+
Test array_map()
65+
66+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
67+
Test is_callable() -- should be silent
68+
bool(true)
69+
Test callable type hint -- should be silent

Zend/tests/closures/closure_from_callable_basic.phpt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ echo $fn(" OK".PHP_EOL);
9696

9797

9898
?>
99-
--EXPECT--
99+
--EXPECTF--
100100
Access public static function OK
101101
Access public static function with different case OK
102102
Access public static function with colon scheme OK
@@ -111,9 +111,17 @@ Instance return private static method as callable OK
111111
Instance return protected static method as callable OK
112112
Subclass closure over parent class protected method OK
113113
Subclass closure over parent class static protected method OK
114-
Access public instance method of parent object through "parent::" OK
115-
Access public instance method of self object through "self::" OK
116-
Access public instance method of parent object through "self::" to parent method OK
117-
Access protected instance method of parent object through "self::" to parent method OK
114+
Access public instance method of parent object through "parent::"
115+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
116+
OK
117+
Access public instance method of self object through "self::"
118+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
119+
OK
120+
Access public instance method of parent object through "self::" to parent method
121+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
122+
OK
123+
Access protected instance method of parent object through "self::" to parent method
124+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
125+
OK
118126
MagicCall __call instance method __call,nonExistentMethod, OK
119127
MagicCall __callStatic static method __callStatic,nonExistentMethod, OK

Zend/tests/closures/closure_from_callable_error.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ catch (\Throwable $t) {
193193
echo "OK\n";
194194

195195
?>
196-
--EXPECT--
196+
--EXPECTF--
197197
Cannot access privateInstance method statically
198198
Cannot access privateInstance method statically with colon scheme
199199
Cannot access privateInstance method
@@ -209,4 +209,6 @@ Subclass cannot closure over parant private static method
209209
Function scope cannot closure over protected instance method
210210
Function scope cannot closure over private instance method
211211
Access private instance method of parent object through "self::" to parent method
212+
213+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
212214
OK

Zend/tests/lsb_011.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ class Test2 extends Test1 {
1919
}
2020
Test2::test();
2121
?>
22-
--EXPECT--
22+
--EXPECTF--
23+
Deprecated: Use of "static" in callables is deprecated in %s on line %d
2324
ok

Zend/tests/lsb_012.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ class Test2 extends Test1 {
1919
}
2020
Test2::test();
2121
?>
22-
--EXPECT--
22+
--EXPECTF--
23+
Deprecated: Use of "static" in callables is deprecated in %s on line %d
2324
ok

Zend/tests/lsb_021.phpt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,20 @@ C::testForward();
3939
C::testNoForward();
4040

4141
?>
42-
--EXPECT--
42+
--EXPECTF--
4343
C
44+
45+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
4446
C
47+
48+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
4549
C
4650
C
51+
52+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
4753
C
54+
55+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
4856
C
4957
A
5058
A

Zend/tests/lsb_022.phpt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,24 @@ class B extends A {
2424
}
2525
B::foo();
2626
?>
27-
--EXPECT--
27+
--EXPECTF--
28+
Deprecated: Use of "static" in callables is deprecated in %s on line %d
2829
B
30+
31+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
32+
33+
Deprecated: Use of "static" in callables is deprecated in %s on line %d
2934
B
35+
36+
Deprecated: Use of "static" in callables is deprecated in %s on line %d
3037
B
38+
39+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
40+
41+
Deprecated: Use of "static" in callables is deprecated in %s on line %d
3142
B
43+
44+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
45+
46+
Deprecated: Use of "static" in callables is deprecated in %s on line %d
3247
B

0 commit comments

Comments
 (0)