Skip to content

Commit 80747d0

Browse files
committed
Implement ReflectionEnum::hasCase()
1 parent 673c858 commit 80747d0

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

ext/reflection/php_reflection.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6475,6 +6475,26 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
64756475
RETURN_COPY_VALUE(&obj);
64766476
}
64776477

6478+
ZEND_METHOD(ReflectionEnum, hasCase)
6479+
{
6480+
reflection_object *intern;
6481+
zend_class_entry *ce;
6482+
zend_string *name;
6483+
6484+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) {
6485+
RETURN_THROWS();
6486+
}
6487+
6488+
GET_REFLECTION_OBJECT_PTR(ce);
6489+
6490+
zend_class_constant *class_const = zend_hash_find_ptr(&ce->constants_table, name);
6491+
if (class_const == NULL) {
6492+
RETURN_FALSE;
6493+
}
6494+
6495+
RETURN_BOOL(class_const->attr & ZEND_CLASS_CONST_IS_CASE);
6496+
}
6497+
64786498
ZEND_METHOD(ReflectionEnum, hasPrimitiveType)
64796499
{
64806500
reflection_object *intern;

ext/reflection/php_reflection.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ private function __construct() {}
674674

675675
final class ReflectionEnum extends ReflectionClass
676676
{
677+
/** @return bool */
678+
public function hasCase(string $name);
679+
677680
/** @return bool */
678681
public function hasPrimitiveType() {}
679682

ext/reflection/php_reflection_arginfo.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 692f70abe2995866533011af18d4fd17b2f074d9 */
2+
* Stub hash: 07fee3b12c632e12a377bac90ee662a752e9e65e */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0)
@@ -493,6 +493,8 @@ ZEND_END_ARG_INFO()
493493

494494
#define arginfo_class_ReflectionAttribute___construct arginfo_class_ReflectionFunctionAbstract_inNamespace
495495

496+
#define arginfo_class_ReflectionEnum_hasCase arginfo_class_ReflectionClass_hasMethod
497+
496498
#define arginfo_class_ReflectionEnum_hasPrimitiveType arginfo_class_ReflectionFunctionAbstract_inNamespace
497499

498500
#define arginfo_class_ReflectionEnum_getPrimitiveType arginfo_class_ReflectionFunctionAbstract_inNamespace
@@ -702,6 +704,7 @@ ZEND_METHOD(ReflectionAttribute, getArguments);
702704
ZEND_METHOD(ReflectionAttribute, newInstance);
703705
ZEND_METHOD(ReflectionAttribute, __clone);
704706
ZEND_METHOD(ReflectionAttribute, __construct);
707+
ZEND_METHOD(ReflectionEnum, hasCase);
705708
ZEND_METHOD(ReflectionEnum, hasPrimitiveType);
706709
ZEND_METHOD(ReflectionEnum, getPrimitiveType);
707710
ZEND_METHOD(ReflectionEnumCase, getScalar);
@@ -1014,6 +1017,7 @@ static const zend_function_entry class_ReflectionAttribute_methods[] = {
10141017

10151018

10161019
static const zend_function_entry class_ReflectionEnum_methods[] = {
1020+
ZEND_ME(ReflectionEnum, hasCase, arginfo_class_ReflectionEnum_hasCase, ZEND_ACC_PUBLIC)
10171021
ZEND_ME(ReflectionEnum, hasPrimitiveType, arginfo_class_ReflectionEnum_hasPrimitiveType, ZEND_ACC_PUBLIC)
10181022
ZEND_ME(ReflectionEnum, getPrimitiveType, arginfo_class_ReflectionEnum_getPrimitiveType, ZEND_ACC_PUBLIC)
10191023
ZEND_FE_END
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
ReflectionEnum::hasCase()
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
const Baz = self::Bar;
9+
}
10+
11+
$reflectionEnum = new ReflectionEnum(Foo::class);
12+
var_dump($reflectionEnum->hasCase('Bar'));
13+
var_dump($reflectionEnum->hasCase('Baz'));
14+
var_dump($reflectionEnum->hasCase('Qux'));
15+
16+
?>
17+
--EXPECT--
18+
bool(true)
19+
bool(false)
20+
bool(false)

0 commit comments

Comments
 (0)