Bug #81517 [Opn]: Bug in enums implementation.
| From: | nikic@php.net | Date: | Mon, 11 Oct 2021 08:49:01 +0000 |
| Subject: | Bug #81517 [Opn]: Bug in enums implementation. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237132@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81517&edit=1
ID: 81517
Updated by: nikic@php.net
Reported by: general at langivi dot technology
Summary: Bug in enums implementation.
Status: Open
Type: Bug
Package: *General Issues
Operating System: linux
PHP Version: 8.1.0RC3
Block user comment: N
Private report: N
New Comment:
Please use the following APIs to work with enums in extensions:
ZEND_API zend_class_entry *zend_register_internal_enum(
const char *name, zend_uchar type, const zend_function_entry *functions);
ZEND_API void zend_enum_add_case(zend_class_entry *ce, zend_string *case_name, zval *value);
ZEND_API void zend_enum_add_case_cstr(zend_class_entry *ce, const char *name, zval *value);
ZEND_API zend_object *zend_enum_get_case(zend_class_entry *ce, zend_string *name);
ZEND_API zend_object *zend_enum_get_case_cstr(zend_class_entry *ce, const char *name);
Additionally, you can declare enums in stubs.
The zend_enum_get_case() functions are used to create enum objects.
However, it is not possible to easily use an enum value as a property default value right now,
because it would require a CONSTANT_AST default value that performs a class constant lookup.
Previous Comments:
------------------------------------------------------------------------
[2021-10-08 18:47:59] general at langivi dot technology
Description:
------------
There is no way to create instance of enum in PHP extension as function is not exported
Test script:
---------------
zval property___status_default_value;
ZVAL_NULL(&property___status_default_value);
zend_enum_new(&property___status_default_value, promise_enum,
zend_string_init("Resolving", sizeof("Resolving") - 1, 1),
NULL);
zend_string * property___status = zend_string_init("status",
sizeof("status") - 1, 1);
Expected result:
----------------
Enum instance should be created.
Actual result:
--------------
php: symbol lookup error: /opt/php/php8/lib/php/extensions/no-debug-non-zts-20210902/fileio.so:
undefined symbol: zend_enum_new
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81517&edit=1