Skip to content

Commit 782a577

Browse files
committed
Make #[\Deprecated]’s code E_USER_DEPRECATED
1 parent 5637768 commit 782a577

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

Zend/tests/attributes/deprecated/004.phpt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ function test() {
1414
try {
1515
test();
1616
} catch (ErrorException $e) {
17-
echo $e;
17+
echo "Caught: ", $e->getMessage(), PHP_EOL;
1818
}
1919

2020
?>
21-
--EXPECTF--
22-
ErrorException: Function test() is deprecated, convert to exception in %s:%d
23-
Stack trace:
24-
#0 %s(%d): {closure:%s:%d}(8192, 'Function test()...', '%s', 12)
25-
#1 {main}%A
21+
--EXPECT--
22+
Caught: Function test() is deprecated, convert to exception
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
#[\Deprecated]: Code is E_USER_DEPRECATED.
3+
--FILE--
4+
<?php
5+
6+
set_error_handler(function (int $errno, string $errstr, ?string $errfile = null, ?int $errline = null) {
7+
var_dump($errno, E_USER_DEPRECATED, $errno === E_USER_DEPRECATED);
8+
});
9+
10+
#[\Deprecated]
11+
function test() {
12+
}
13+
14+
test();
15+
16+
?>
17+
--EXPECT--
18+
int(16384)
19+
int(16384)
20+
bool(true)

Zend/zend_execute.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,15 +1740,17 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_functi
17401740
}
17411741
}
17421742

1743+
int code = fbc->type == ZEND_INTERNAL_FUNCTION ? E_DEPRECATED : E_USER_DEPRECATED;
1744+
17431745
if (message_suffix != NULL) {
17441746
if (fbc->common.scope) {
1745-
zend_error(E_DEPRECATED, "Method %s::%s() is deprecated, %s",
1747+
zend_error(code, "Method %s::%s() is deprecated, %s",
17461748
ZSTR_VAL(fbc->common.scope->name),
17471749
ZSTR_VAL(fbc->common.function_name),
17481750
ZSTR_VAL(message_suffix)
17491751
);
17501752
} else {
1751-
zend_error(E_DEPRECATED, "Function %s() is deprecated, %s",
1753+
zend_error(code, "Function %s() is deprecated, %s",
17521754
ZSTR_VAL(fbc->common.function_name),
17531755
ZSTR_VAL(message_suffix)
17541756
);
@@ -1757,12 +1759,12 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_functi
17571759
zend_string_release(message_suffix);
17581760
} else {
17591761
if (fbc->common.scope) {
1760-
zend_error(E_DEPRECATED, "Method %s::%s() is deprecated",
1762+
zend_error(code, "Method %s::%s() is deprecated",
17611763
ZSTR_VAL(fbc->common.scope->name),
17621764
ZSTR_VAL(fbc->common.function_name)
17631765
);
17641766
} else {
1765-
zend_error(E_DEPRECATED, "Function %s() is deprecated", ZSTR_VAL(fbc->common.function_name));
1767+
zend_error(code, "Function %s() is deprecated", ZSTR_VAL(fbc->common.function_name));
17661768
}
17671769
}
17681770
}

0 commit comments

Comments
 (0)