Skip to content

Commit ea9c9dc

Browse files
committed
Add support for adding the #[\Deprecated] attribute to class constants to stubs
1 parent c0b03e3 commit ea9c9dc

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

build/gen_stub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,6 +2861,13 @@ protected function getFlagsByPhpVersion(): array
28612861
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_DEPRECATED", PHP_80_VERSION_ID);
28622862
}
28632863

2864+
foreach ($this->attributes as $attr) {
2865+
if ($attr->class === "Deprecated") {
2866+
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_DEPRECATED", PHP_80_VERSION_ID);
2867+
break;
2868+
}
2869+
}
2870+
28642871
if ($this->flags & Modifiers::FINAL) {
28652872
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_FINAL", PHP_81_VERSION_ID);
28662873
}

ext/zend_test/test.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class _ZendTestClass implements _ZendTestInterface {
4343
*/
4444
public const int ZEND_TEST_DEPRECATED = 42;
4545

46+
#[\Deprecated(message: "custom message")]
47+
public const int ZEND_TEST_DEPRECATED_ATTR = 42;
48+
4649
/** @var mixed */
4750
public static $_StaticProp;
4851
public static int $staticIntProp = 123;

ext/zend_test/test_arginfo.h

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/zend_test/tests/attribute-deprecated.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ zend_test_deprecated_attr();
99

1010
$reflection = new ReflectionFunction('zend_test_deprecated_attr');
1111
var_dump($reflection->getAttributes()[0]->newInstance());
12+
var_dump($reflection->isDeprecated());
13+
14+
_ZendTestClass::ZEND_TEST_DEPRECATED_ATTR;
15+
16+
$reflection = new ReflectionClassConstant('_ZendTestClass', 'ZEND_TEST_DEPRECATED_ATTR');
17+
var_dump($reflection->getAttributes()[0]->newInstance());
18+
var_dump($reflection->isDeprecated());
19+
1220
?>
1321
--EXPECTF--
1422
Deprecated: Function zend_test_deprecated() is deprecated in %s on line %d
@@ -18,3 +26,11 @@ object(Deprecated)#%d (1) {
1826
["message"]=>
1927
string(14) "custom message"
2028
}
29+
bool(true)
30+
31+
Deprecated: Constant _ZendTestClass::ZEND_TEST_DEPRECATED_ATTR is deprecated, custom message in %s on line %d
32+
object(Deprecated)#%d (1) {
33+
["message"]=>
34+
string(14) "custom message"
35+
}
36+
bool(true)

0 commit comments

Comments
 (0)