Skip to content

Commit 3af29f1

Browse files
committed
Deprecate ["C1", "C2::method"] style callables
1 parent 51d5e88 commit 3af29f1

File tree

9 files changed

+37
-25
lines changed

9 files changed

+37
-25
lines changed

Zend/tests/bug48770.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ $c->callFuncInParent('Which function will be called??');
3131

3232
?>
3333
--EXPECTF--
34-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
34+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
3535
B::func called

Zend/tests/bug48770_2.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ $c->func('This should work!');
5454

5555
?>
5656
--EXPECTF--
57-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
57+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
5858
string(27) "B::func2: This should work!"
5959

60-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
60+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
6161
string(27) "B::func3: This should work!"
6262

63-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
63+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
6464
call_user_func_array(): Argument #1 ($callback) must be a valid callback, cannot access private method B::func22()
6565

66-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
66+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
6767
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ $c->func('This should work!');
4545

4646
?>
4747
--EXPECTF--
48-
Deprecated: Use of "self" in callables is deprecated in %s on line %d
48+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
4949
string(27) "B::func2: This should work!"
5050

51-
Deprecated: Use of "self" in callables is deprecated in %s on line %d
51+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
5252
string(27) "B::func3: This should work!"
5353

54-
Deprecated: Use of "self" in callables is deprecated in %s on line %d
54+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
5555
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ C::test();
3838
string(1) "B"
3939
string(1) "A"
4040

41-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
41+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
4242
string(1) "A"
4343
string(1) "B"
4444
string(1) "A"
4545

46-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
46+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
4747
string(1) "A"

Zend/tests/callable_self_parent_static_deprecation.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class B extends A {
1919
call_user_func(["B", "self::foo"]);
2020
call_user_func(["B", "parent::foo"]);
2121
call_user_func(["B", "static::foo"]);
22+
call_user_func(["B", "A::foo"]);
2223

2324
// Also applies to other things performing calls
2425
echo "Test array_map()\n";
@@ -53,11 +54,13 @@ Deprecated: Use of "parent" in callables is deprecated in %s on line %d
5354

5455
Deprecated: Use of "static" in callables is deprecated in %s on line %d
5556

56-
Deprecated: Use of "self" in callables is deprecated in %s on line %d
57+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
5758

58-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
59+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
5960

60-
Deprecated: Use of "static" in callables is deprecated in %s on line %d
61+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
62+
63+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
6164
Test array_map()
6265

6366
Deprecated: Use of "self" in callables is deprecated in %s on line %d

Zend/zend_API.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,7 +3291,7 @@ static zend_always_inline zend_class_entry *get_scope(zend_execute_data *frame)
32913291
return frame && frame->func ? frame->func->common.scope : NULL;
32923292
}
32933293

3294-
static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *scope, zend_execute_data *frame, zend_fcall_info_cache *fcc, bool *strict_class, char **error) /* {{{ */
3294+
static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *scope, zend_execute_data *frame, zend_fcall_info_cache *fcc, bool *strict_class, char **error, bool suppress_deprecation) /* {{{ */
32953295
{
32963296
bool ret = 0;
32973297
zend_class_entry *ce;
@@ -3307,7 +3307,7 @@ 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) {
3310+
if (error && !suppress_deprecation) {
33113311
zend_error(E_DEPRECATED, "Use of \"self\" in callables is deprecated");
33123312
}
33133313
fcc->called_scope = zend_get_called_scope(frame);
@@ -3326,7 +3326,7 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
33263326
} else if (!scope->parent) {
33273327
if (error) *error = estrdup("cannot access \"parent\" when current class scope has no parent");
33283328
} else {
3329-
if (error) {
3329+
if (error && !suppress_deprecation) {
33303330
zend_error(E_DEPRECATED, "Use of \"parent\" in callables is deprecated");
33313331
}
33323332
fcc->called_scope = zend_get_called_scope(frame);
@@ -3346,7 +3346,7 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
33463346
if (!called_scope) {
33473347
if (error) *error = estrdup("cannot access \"static\" when no class scope is active");
33483348
} else {
3349-
if (error) {
3349+
if (error && !suppress_deprecation) {
33503350
zend_error(E_DEPRECATED, "Use of \"static\" in callables is deprecated");
33513351
}
33523352
fcc->called_scope = called_scope;
@@ -3481,7 +3481,7 @@ static zend_always_inline bool zend_is_callable_check_func(int check_flags, zval
34813481
fcc->called_scope = fcc->object ? fcc->object->ce : fcc->calling_scope;
34823482
}
34833483
strict_class = 1;
3484-
} else if (!zend_is_callable_check_class(cname, scope, frame, fcc, &strict_class, error)) {
3484+
} else if (!zend_is_callable_check_class(cname, scope, frame, fcc, &strict_class, error, ce_org != NULL)) {
34853485
zend_string_release_ex(cname, 0);
34863486
return 0;
34873487
}
@@ -3492,6 +3492,10 @@ static zend_always_inline bool zend_is_callable_check_func(int check_flags, zval
34923492
if (error) zend_spprintf(error, 0, "class %s is not a subclass of %s", ZSTR_VAL(ce_org->name), ZSTR_VAL(fcc->calling_scope->name));
34933493
return 0;
34943494
}
3495+
if (ce_org && error) {
3496+
zend_error(E_DEPRECATED,
3497+
"Callables of the form [\"C1\", \"C2::method\"] are deprecated");
3498+
}
34953499
mname = zend_string_init(Z_STRVAL_P(callable) + clen + 2, mlen, 0);
34963500
} else if (ce_org) {
34973501
/* Try to fetch find static method of given class. */
@@ -3765,7 +3769,7 @@ ZEND_API bool zend_is_callable_at_frame(
37653769
return 1;
37663770
}
37673771

3768-
if (!zend_is_callable_check_class(Z_STR_P(obj), get_scope(frame), frame, fcc, &strict_class, error)) {
3772+
if (!zend_is_callable_check_class(Z_STR_P(obj), get_scope(frame), frame, fcc, &strict_class, error, false)) {
37693773
return 0;
37703774
}
37713775
} else {

ext/standard/tests/general_functions/bug40398.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ new Derived_6('6');
7474

7575
?>
7676
--EXPECTF--
77+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
7778
Base::__construct(1)
7879

79-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
80+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
8081
Base::__construct(2)
8182
Base::__construct(3)
8283

ext/standard/tests/general_functions/callbacks_001.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ Deprecated: Use of "parent" in callables is deprecated in %s on line %d
9090
B
9191
C|parent::who
9292

93-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
93+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
9494
B
9595
B|parent::who
9696

97-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
97+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
9898
A
9999
E|parent::who
100100

101-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
101+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
102102
D
103103
A|who
104104
A
@@ -113,9 +113,11 @@ Deprecated: Use of "parent" in callables is deprecated in %s on line %d
113113
O
114114
P|parent::who
115115

116-
Deprecated: Use of "parent" in callables is deprecated in %s on line %d
116+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
117117
O
118118
$this|O::who
119+
120+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
119121
O
120122
$this|B::who
121123
call_user_func(): Argument #1 ($callback) must be a valid callback, class P is not a subclass of B

tests/classes/abstract_user_call.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ try {
2727
}
2828

2929
?>
30-
--EXPECT--
30+
--EXPECTF--
3131
test::func()
32+
33+
Deprecated: Callables of the form ["C1", "C2::method"] are deprecated in %s on line %d
3234
call_user_func(): Argument #1 ($callback) must be a valid callback, cannot call abstract method test_base::func()

0 commit comments

Comments
 (0)