|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81517 Cannot use enum as property default in internal class
Submitted: 2021-10-08 18:47 UTC Modified: 2021-10-12 12:12 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: general at langivi dot technology Assigned:
Status: Open Package: *General Issues
PHP Version: 8.1.0RC3 OS: linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-10-08 18:47 UTC] general at langivi dot technology
There is no way to create instance of enum in PHP extension as function is not exported 

Test script:
    zval 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/ undefined symbol: zend_enum_new


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-11 08:49 UTC]
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.
 [2021-10-12 12:12 UTC]
-Summary: Bug in enums implementation. +Summary: Cannot use enum as property default in internal class
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 20 08:01:28 2024 UTC