Skip to content

Commit 1fac0ce

Browse files
committed
WIP is_enum
1 parent 589fee9 commit 1fac0ce

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

Zend/tests/enum/021.phpt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
--TEST--
2-
Enum implements Enum interface
2+
is_enum
33
--FILE--
44
<?php
55

66
enum Foo {
77
case Bar;
88
}
99

10-
var_dump(Foo::Bar instanceof Enum);
10+
class Baz {}
11+
12+
var_dump(is_enum(Foo::class));
13+
var_dump(is_enum(Foo::Bar::class));
14+
var_dump(is_enum(Baz::class));
1115

1216
?>
1317
--EXPECT--
1418
bool(true)
19+
bool(true)
20+
bool(false)

Zend/zend_builtin_functions.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,11 @@ ZEND_FUNCTION(trait_exists)
10611061
}
10621062
/* }}} */
10631063

1064+
ZEND_FUNCTION(is_enum)
1065+
{
1066+
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_ENUM|ZEND_ACC_ENUM_CASE, 0);
1067+
}
1068+
10641069
/* {{{ Checks if the function exists */
10651070
ZEND_FUNCTION(function_exists)
10661071
{

Zend/zend_builtin_functions.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function get_parent_class(object|string $object_or_class = UNKNOWN): string|fals
3636
/** @param object|string $object_or_class */
3737
function is_subclass_of(mixed $object_or_class, string $class, bool $allow_string = true): bool {}
3838

39+
function is_enum(string $enum, bool $autoload = true): bool {}
40+
3941
/** @param object|string $object_or_class */
4042
function is_a(mixed $object_or_class, string $class, bool $allow_string = false): bool {}
4143

Zend/zend_builtin_functions_arginfo.h

Lines changed: 8 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: b09e9199a21595a3b6f6c02db81c8e22c36c277f */
2+
* Stub hash: 960bb56c1108bb7b5b826976490c7936fc8460b2 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_version, 0, 0, IS_STRING, 0)
55
ZEND_END_ARG_INFO()
@@ -63,6 +63,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_is_subclass_of, 0, 2, _IS_BOOL,
6363
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, allow_string, _IS_BOOL, 0, "true")
6464
ZEND_END_ARG_INFO()
6565

66+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_is_enum, 0, 1, _IS_BOOL, 0)
67+
ZEND_ARG_TYPE_INFO(0, enum, IS_STRING, 0)
68+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, autoload, _IS_BOOL, 0, "true")
69+
ZEND_END_ARG_INFO()
70+
6671
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_is_a, 0, 2, _IS_BOOL, 0)
6772
ZEND_ARG_TYPE_INFO(0, object_or_class, IS_MIXED, 0)
6873
ZEND_ARG_TYPE_INFO(0, class, IS_STRING, 0)
@@ -238,6 +243,7 @@ ZEND_FUNCTION(property_exists);
238243
ZEND_FUNCTION(class_exists);
239244
ZEND_FUNCTION(interface_exists);
240245
ZEND_FUNCTION(trait_exists);
246+
ZEND_FUNCTION(is_enum);
241247
ZEND_FUNCTION(function_exists);
242248
ZEND_FUNCTION(class_alias);
243249
ZEND_FUNCTION(get_included_files);
@@ -288,6 +294,7 @@ static const zend_function_entry ext_functions[] = {
288294
ZEND_FE(get_called_class, arginfo_get_called_class)
289295
ZEND_FE(get_parent_class, arginfo_get_parent_class)
290296
ZEND_FE(is_subclass_of, arginfo_is_subclass_of)
297+
ZEND_FE(is_enum, arginfo_is_enum)
291298
ZEND_FE(is_a, arginfo_is_a)
292299
ZEND_FE(get_class_vars, arginfo_get_class_vars)
293300
ZEND_FE(get_object_vars, arginfo_get_object_vars)

0 commit comments

Comments
 (0)