Skip to content

Commit e5e7fea

Browse files
committed
Process #[Deprecated] reason message.
1 parent dd59e48 commit e5e7fea

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

Zend/tests/attributes/deprecated_001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ test();
1818
test2();
1919
call_user_func("test");
2020
--EXPECTF--
21-
Deprecated: Function test is deprecated in %s
21+
Deprecated: Function test() is deprecated in %s
2222

23-
Deprecated: Function test2 is deprecated use test() instead in %s
23+
Deprecated: Function test2() is deprecated, use test() instead in %s
2424

25-
Deprecated: Function test is deprecated in %s
25+
Deprecated: Function test() is deprecated in %s

Zend/zend_execute.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "zend_smart_str.h"
4343
#include "zend_observer.h"
4444
#include "zend_system_id.h"
45+
#include "zend_attributes.h"
4546

4647
/* Virtual current working directory support */
4748
#include "zend_virtual_cwd.h"
@@ -1489,13 +1490,43 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_property_read(z
14891490

14901491
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_function *fbc)
14911492
{
1492-
if (fbc->common.scope) {
1493-
zend_error(E_DEPRECATED, "Method %s::%s() is deprecated",
1494-
ZSTR_VAL(fbc->common.scope->name),
1495-
ZSTR_VAL(fbc->common.function_name)
1496-
);
1493+
zend_attribute *deprecated;
1494+
zend_string *reason = NULL;
1495+
1496+
if (fbc->common.attributes != NULL) {
1497+
deprecated = zend_get_attribute_str(fbc->common.attributes, "deprecated", sizeof("deprecated")-1);
1498+
1499+
if (deprecated->argc >= 1) {
1500+
zval message;
1501+
1502+
if (FAILURE != zend_get_attribute_value(&message, deprecated, 0, fbc->common.scope)) {
1503+
reason = Z_STR(message);
1504+
}
1505+
}
1506+
}
1507+
1508+
if (reason != NULL) {
1509+
if (fbc->common.scope) {
1510+
zend_error(E_DEPRECATED, "Method %s::%s() is deprecated, %s",
1511+
ZSTR_VAL(fbc->common.scope->name),
1512+
ZSTR_VAL(fbc->common.function_name),
1513+
ZSTR_VAL(reason)
1514+
);
1515+
} else {
1516+
zend_error(E_DEPRECATED, "Function %s() is deprecated, %s",
1517+
ZSTR_VAL(fbc->common.function_name),
1518+
ZSTR_VAL(reason)
1519+
);
1520+
}
14971521
} else {
1498-
zend_error(E_DEPRECATED, "Function %s() is deprecated", ZSTR_VAL(fbc->common.function_name));
1522+
if (fbc->common.scope) {
1523+
zend_error(E_DEPRECATED, "Method %s::%s() is deprecated",
1524+
ZSTR_VAL(fbc->common.scope->name),
1525+
ZSTR_VAL(fbc->common.function_name)
1526+
);
1527+
} else {
1528+
zend_error(E_DEPRECATED, "Function %s() is deprecated", ZSTR_VAL(fbc->common.function_name));
1529+
}
14991530
}
15001531
}
15011532

0 commit comments

Comments
 (0)