Skip to content

Commit 22dc09c

Browse files
committed
Fix #[\Deprecated] for __call() and __callStatic()
Fixes #17597.
1 parent 7f321a1 commit 22dc09c

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ PHP NEWS
2020
(nielsdos, ilutov)
2121
. Fix may_have_extra_named_args flag for ZEND_AST_UNPACK. (nielsdos)
2222
. Fix NULL arithmetic in System V shared memory emulation for Windows. (cmb)
23+
. Fixed bug GH-17597 (#[\Deprecated] does not work for __call() and
24+
__callStatic()). (timwolla)
2325

2426
- DOM:
2527
. Fixed bug GH-17397 (Assertion failure ext/dom/php_dom.c). (nielsdos)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
#[\Deprecated]: __call() and __callStatic()
3+
--FILE--
4+
<?php
5+
6+
class Clazz {
7+
#[\Deprecated]
8+
function __call(string $name, array $params) {
9+
}
10+
11+
#[\Deprecated("due to some reason")]
12+
static function __callStatic(string $name, array $params) {
13+
}
14+
}
15+
16+
$cls = new Clazz();
17+
$cls->test();
18+
Clazz::test2();
19+
20+
?>
21+
--EXPECTF--
22+
Deprecated: Method Clazz::test() is deprecated in %s
23+
24+
Deprecated: Method Clazz::test2() is deprecated, due to some reason in %s on line %d

Zend/zend_object_handlers.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,12 @@ ZEND_API zend_function *zend_get_call_trampoline_func(const zend_class_entry *ce
16171617
func->fn_flags = ZEND_ACC_CALL_VIA_TRAMPOLINE
16181618
| ZEND_ACC_PUBLIC
16191619
| ZEND_ACC_VARIADIC
1620-
| (fbc->common.fn_flags & ZEND_ACC_RETURN_REFERENCE);
1620+
| (fbc->common.fn_flags & (ZEND_ACC_RETURN_REFERENCE|ZEND_ACC_DEPRECATED));
1621+
if (fbc->common.attributes) {
1622+
func->attributes = zend_array_dup(fbc->common.attributes);
1623+
} else {
1624+
func->attributes = NULL;
1625+
}
16211626
if (is_static) {
16221627
func->fn_flags |= ZEND_ACC_STATIC;
16231628
}

Zend/zend_object_handlers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ ZEND_API bool ZEND_FASTCALL zend_asymmetric_property_has_set_access(const zend_p
339339
} while (0)
340340

341341
#define zend_free_trampoline(func) do { \
342+
if ((func)->common.attributes) { \
343+
zend_array_destroy((func)->common.attributes); \
344+
(func)->common.attributes = NULL; \
345+
} \
342346
if ((func) == &EG(trampoline)) { \
343347
EG(trampoline).common.function_name = NULL; \
344348
} else { \

0 commit comments

Comments
 (0)