Skip to content

Commit 98e4394

Browse files
committed
Deprecate self/parent/static in callables
1 parent 6b8d415 commit 98e4394

21 files changed

+136
-25
lines changed

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: Use of "parent" in callables is 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: Use of "parent" in callables is deprecated in %s on line %d
5758
string(27) "B::func2: This should work!"
59+
60+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
5861
string(27) "B::func3: This should work!"
62+
63+
Deprecated: Use of "parent" in callables is 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: Use of "parent" in callables is 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: Use of "self" in callables is deprecated in %s on line %d
4849
string(27) "B::func2: This should work!"
50+
51+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
4952
string(27) "B::func3: This should work!"
53+
54+
Deprecated: Use of "self" in callables is 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: Use of "parent" in callables is deprecated in %s on line %d
4042
string(1) "A"
4143
string(1) "B"
4244
string(1) "A"
45+
46+
Deprecated: Use of "parent" in callables is 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

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

Zend/zend_API.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,6 +3307,9 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
33073307
if (!scope) {
33083308
if (error) *error = estrdup("cannot access \"self\" when no class scope is active");
33093309
} else {
3310+
if (error) {
3311+
zend_error(E_DEPRECATED, "Use of \"self\" in callables is deprecated");
3312+
}
33103313
fcc->called_scope = zend_get_called_scope(frame);
33113314
if (!fcc->called_scope || !instanceof_function(fcc->called_scope, scope)) {
33123315
fcc->called_scope = scope;
@@ -3323,6 +3326,9 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
33233326
} else if (!scope->parent) {
33243327
if (error) *error = estrdup("cannot access \"parent\" when current class scope has no parent");
33253328
} else {
3329+
if (error) {
3330+
zend_error(E_DEPRECATED, "Use of \"parent\" in callables is deprecated");
3331+
}
33263332
fcc->called_scope = zend_get_called_scope(frame);
33273333
if (!fcc->called_scope || !instanceof_function(fcc->called_scope, scope->parent)) {
33283334
fcc->called_scope = scope->parent;
@@ -3340,6 +3346,9 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
33403346
if (!called_scope) {
33413347
if (error) *error = estrdup("cannot access \"static\" when no class scope is active");
33423348
} else {
3349+
if (error) {
3350+
zend_error(E_DEPRECATED, "Use of \"static\" in callables is deprecated");
3351+
}
33433352
fcc->called_scope = called_scope;
33443353
fcc->calling_scope = called_scope;
33453354
if (!fcc->object) {

ext/standard/tests/class_object/forward_static_call_001.phpt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,20 @@ echo "-\n";
5757
C::test3();
5858

5959
?>
60-
--EXPECT--
60+
--EXPECTF--
6161
A
6262
-
6363
B
64+
65+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
6466
B
6567
-
6668
B
69+
70+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
6771
B
72+
73+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
6874
B
6975
-
7076
B
@@ -74,7 +80,11 @@ C
7480
C
7581
-
7682
B
83+
84+
Deprecated: Use of "self" in callables is deprecated in %s on line %d
7785
B
86+
87+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
7888
C
7989
-
8090
B

ext/standard/tests/class_object/forward_static_call_003.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ echo "-\n";
3838
C::test();
3939

4040
?>
41-
--EXPECT--
41+
--EXPECTF--
4242
A
4343
-
4444
B
45+
46+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
4547
B
4648
-
4749
C
4850
B
51+
52+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
4953
B

ext/standard/tests/general_functions/bug40398.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@ new Derived_5('5');
7373
new Derived_6('6');
7474

7575
?>
76-
--EXPECT--
76+
--EXPECTF--
7777
Base::__construct(1)
78+
79+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
7880
Base::__construct(2)
7981
Base::__construct(3)
82+
83+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
8084
Base::__construct(4)
8185
Base::__construct(5)
86+
87+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
8288
Base::__construct(6)

ext/standard/tests/general_functions/callbacks_001.phpt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,22 @@ $o = new P;
8383
$o->test();
8484

8585
?>
86-
--EXPECT--
86+
--EXPECTF--
8787
parent|who
88+
89+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
8890
B
8991
C|parent::who
92+
93+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
9094
B
9195
B|parent::who
96+
97+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
9298
A
9399
E|parent::who
100+
101+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
94102
D
95103
A|who
96104
A
@@ -100,8 +108,12 @@ B|who2
100108
A
101109
===FOREIGN===
102110
parent|who
111+
112+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
103113
O
104114
P|parent::who
115+
116+
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
105117
O
106118
$this|O::who
107119
O

0 commit comments

Comments
 (0)