Skip to content

Expose zend_reflection_property_set_raw_value, zend_reflection_property_set_raw_value_without_lazy_initialization#21763

Open
arnaud-lb wants to merge 2 commits intophp:masterfrom
arnaud-lb:expose-refl-set-raw-value
Open

Expose zend_reflection_property_set_raw_value, zend_reflection_property_set_raw_value_without_lazy_initialization#21763
arnaud-lb wants to merge 2 commits intophp:masterfrom
arnaud-lb:expose-refl-set-raw-value

Conversation

@arnaud-lb
Copy link
Copy Markdown
Member

@arnaud-lb arnaud-lb commented Apr 15, 2026

This exposes the functionality of ReflectionProperty::setRawValue() and ReflectionProperty::setRawValueWithoutLazyInitialiation() to C extensions.

Test failure unrelated.

…ty_set_raw_value_without_lazy_initialization
@arnaud-lb arnaud-lb changed the title [wip] Expose zend_reflection_property_set_raw_value, zend_reflection_property_set_raw_value_without_lazy_initialization Expose zend_reflection_property_set_raw_value, zend_reflection_property_set_raw_value_without_lazy_initialization Apr 15, 2026
@arnaud-lb arnaud-lb marked this pull request as ready for review April 15, 2026 10:18
nicolas-grekas added a commit to symfony/php-ext-deepclone that referenced this pull request Apr 15, 2026
…lable

PHP 8.6 exposes zend_reflection_property_set_raw_value{,_without_lazy_initialization}
as PHPAPI (php/php-src#21763), moving the lazy-prop
bookkeeping into ext/reflection. Use the PHPAPI direct on 8.6+ and keep the
userland ReflectionProperty round-trip as a fallback for 8.4 / 8.5.

Depends on php/php-src#21763 landing; holding here until the patch is merged
and the target PHP version is known.
nicolas-grekas added a commit to symfony/php-ext-deepclone that referenced this pull request Apr 15, 2026
…lable

PHP 8.6 exposes zend_reflection_property_set_raw_value{,_without_lazy_initialization}
as PHPAPI (php/php-src#21763), moving the lazy-prop
bookkeeping into ext/reflection. Use the PHPAPI direct on 8.6+ and keep the
userland ReflectionProperty round-trip as a fallback for 8.4 / 8.5.

Depends on php/php-src#21763 landing; holding here until the patch is merged
and the target PHP version is known.
@DanielEScherzer
Copy link
Copy Markdown
Member

Not sure the current interface is the best to expose, e.g. the void *cache_slot[3] parameters are not really documented

What is the issue with having other extensions just call the reflection methods via the normal mechanism for calling class methods?

@nicolas-grekas
Copy link
Copy Markdown
Contributor

What is the issue with having other extensions just call the reflection methods via the normal mechanism for calling class methods

CPU overhead!

@arnaud-lb
Copy link
Copy Markdown
Member Author

@DanielEScherzer I've documented the cache_slot parameter in the comment above the declaration of zend_reflection_property_set_raw_value. It is not uncommon to find such cache_slot parameter in the code base, on functions related to property accesses.

If you prefer, I can change the API to something like this:

typedef reflection_object zend_reflection_property;

PHPAPI zend_reflection_property *zend_reflection_property_create(zend_class_entry *ce, zend_string *name);
PHPAPI void zend_reflection_property_set_raw_value(zend_reflection_property *refl_prop, zend_object *object, zval *value);

What is the issue with having other extensions just call the reflection methods via the normal mechanism for calling class methods?

In addition to being faster, this also provides a nicer API. Instantiating objects and calling methods is not straightforward in C.

nicolas-grekas added a commit to symfony/php-ext-deepclone that referenced this pull request Apr 16, 2026
…lable

PHP 8.6 exposes zend_reflection_property_set_raw_value{,_without_lazy_initialization}
as PHPAPI (php/php-src#21763), moving the lazy-prop
bookkeeping into ext/reflection. Use the PHPAPI direct on 8.6+ and keep the
userland ReflectionProperty round-trip as a fallback for 8.4 / 8.5.

Depends on php/php-src#21763 landing; holding here until the patch is merged
and the target PHP version is known.
@Girgias
Copy link
Copy Markdown
Member

Girgias commented Apr 16, 2026

The other thing to mention is calling a "PHP" function/method from C AFAIK requires setting up new VM stacks compared to "just" running in a loop. The other thing is that for global functions those can be disabled by an INI setting. (For classes and class methods that's no longer an issue since 8.5 as the disable_class INI setting got removed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants