Skip to content

Lower-level extension object read/write hooks for non-standard property backing stores #17512

@dktapps

Description

@dktapps

Description

I maintain a threading extension. One of the features offered by the extension is a ThreadSafe class. Implementing this requires overriding all of the default property read/write handlers to push values into a thread-safe store on write and pull them out on read. (This comes with some limitations of course, but that's not relevant for this issue.)

Unfortunately, because of the implementation of the likes of zend_std_read_property and friends, it's horribly inconvenient to mirror the behaviour of standard objects. In PHP 8.4 in particular, I find myself having to copy-paste large sections of php-src code to deal with property hooks.
This is because lots of logic about visibility, read-only, __get & __set, property hooks etc are baked directly into the std handlers.

This issue is requesting the introduction of more low-level property read/write hooks to allow extension objects to work with a different property backing store than the default, without losing all of the features provided by php-src for normal objects (or needing to copy-paste code).

Alternative solutions

I've spent several days recently working on a way to have the extension wrap around the default property handlers, but because there's so many behaviours (__set, property hooks, etc) I still found myself needing to duplicate various parts of the logic to get the behaviour to match up. There's 250 lines of complex logic in zend_std_write_property alone.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions