Skip to content

Commit 3b5986d

Browse files
committed
Implement GH-12908: Show attribute name/class in ReflectionAttribute dump
This is consistent with how many other Reflection classes have a name field, and it makes debugging easier. Closes GH-12908. Closes GH-12917.
1 parent 47b05de commit 3b5986d

File tree

7 files changed

+47
-2
lines changed

7 files changed

+47
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ POSIX:
111111
PSpell:
112112
. Moved to PECL. (Derick Rethans)
113113

114+
Reflection:
115+
. Implement GH-12908 (Show attribute name/class in ReflectionAttribute dump).
116+
(nielsdos)
117+
114118
SimpleXML:
115119
. Fixed bug GH-12192 (SimpleXML infinite loop when getName() is called
116120
within foreach). (nielsdos)

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ PDO_SQLITE:
202202
. Added constant POSIX_SC_CHILD_MAX
203203
. Added constant POSIX_SC_CLK_TCK
204204

205+
- Reflection:
206+
. ReflectionAttribute now contains a $name property to improve the debugging
207+
experience.
208+
205209
- SOAP:
206210
. Added support for clark notation for namespaces in class map.
207211
It is now possible to specify entries in a class map with clark notation

Zend/tests/attributes/031_backtrace.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ array(2) {
5252
["class"]=>
5353
string(19) "ReflectionAttribute"
5454
["object"]=>
55-
object(ReflectionAttribute)#2 (0) {
55+
object(ReflectionAttribute)#2 (1) {
56+
["name"]=>
57+
string(11) "MyAttribute"
5658
}
5759
["type"]=>
5860
string(2) "->"

ext/reflection/php_reflection.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ static void reflection_attribute_factory(zval *object, HashTable *attributes, ze
11221122
reference->target = target;
11231123
intern->ptr = reference;
11241124
intern->ref_type = REF_TYPE_ATTRIBUTE;
1125+
ZVAL_STR_COPY(reflection_prop_name(object), data->name);
11251126
}
11261127
/* }}} */
11271128

ext/reflection/php_reflection.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ class ReflectionAttribute implements Reflector
764764
/** @cvalue REFLECTION_ATTRIBUTE_IS_INSTANCEOF */
765765
public const int IS_INSTANCEOF = UNKNOWN;
766766

767+
public string $name;
768+
767769
public function getName(): string {}
768770
public function getTarget(): int {}
769771
public function isRepeated(): bool {}

ext/reflection/php_reflection_arginfo.h

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

ext/reflection/tests/gh12908.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-12908 (Show attribute name/class in ReflectionAttribute dump)
3+
--FILE--
4+
<?php
5+
6+
#[\AllowDynamicProperties, \Foo]
7+
class Test {
8+
}
9+
10+
print_r((new ReflectionClass(Test::class))->getAttributes());
11+
12+
?>
13+
--EXPECT--
14+
Array
15+
(
16+
[0] => ReflectionAttribute Object
17+
(
18+
[name] => AllowDynamicProperties
19+
)
20+
21+
[1] => ReflectionAttribute Object
22+
(
23+
[name] => Foo
24+
)
25+
26+
)

0 commit comments

Comments
 (0)