php-src/ext/reflection/tests/ReflectionEnumUnitCase_getDocComment.phpt
Tyson Andre d60bc0e2d9
Support doc comments on enum cases (#6984)
Because php supports doc comments on class constants, I believe it would also
make sense to support them on enum cases.

I don't have strong opinions about whether attributes should be moved to be the
last element or whether the doc comment should go after the attribute,
but the ast will likely change again before php 8.1 is stable.
So far, all attributes are the last ast child node.

I didn't notice that doc comments weren't implemented due to
https://github.com/php/php-src/pull/6489 being a large change.

https://wiki.php.net/rfc/enumerations
did not mention whether or not doc comments were meant to be supported
2021-05-14 15:25:03 -04:00

23 lines
628 B
PHP

--TEST--
ReflectionEnumUnitCase::getDocComment()
--FILE--
<?php
// enum cases should support doc comments, like class constants.
enum Foo {
/** Example doc comment */
case Bar;
case Baz;
}
var_dump((new ReflectionEnumUnitCase(Foo::class, 'Bar'))->getDocComment());
var_dump((new ReflectionEnumUnitCase(Foo::class, 'Baz'))->getDocComment());
var_dump((new ReflectionClassConstant(Foo::class, 'Bar'))->getDocComment());
var_dump((new ReflectionClassConstant(Foo::class, 'Baz'))->getDocComment());
?>
--EXPECT--
string(26) "/** Example doc comment */"
bool(false)
string(26) "/** Example doc comment */"
bool(false)