php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: general at langivi dot technology
New email:
PHP Version: OS:

 

 [2021-10-08 18:47 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-11 08:49 UTC] nikic@php.net
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] nikic@php.net
-Summary: Bug in enums implementation. +Summary: Cannot use enum as property default in internal class
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 07:01:28 2025 UTC