Re: Built-in decorator attribute?

From: Date: Tue, 16 Mar 2021 01:37:50 +0000
Subject: Re: Built-in decorator attribute?
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-113553@lists.php.net to get a copy of this message
I was able to get a proof of concept of the following at https://github.com/iggyvolz/hooks:

On 3/14/2021 7:52 AM, Benjamin Eberlei wrote:
However, as functionality it could be provided as an extension first for a proof of concept. The ingredients are all there, it doesn't need to be in core: 1. Register an internal attribute, see my #[Deprecated] PR as an example https://github.com/php/php-src/pull/6521 2. Register a zend_observer as a first step, that detects functions/methods with a new #[Intercept] or whatever attribute you want and registers observer callbacks. See ext/zend_test https://github.com/php/php-src/blob/master/ext/zend_test/test.c or tideways/php-xhprof-extension: https://github.com/tideways/php-xhprof-extension/blob/master/tideways_xhprof.c#L30-L57 3. Use C API zend_call_function in the observer to call your interceptor. Cobbling this together as a Frankestein monster from existing code should be achievable even if you haven't worked with PHP core yet imho. This could replace the php-aop extension that isn't maintained anymore. Using a zend_obserer would only allow you to register a before and after hook, the alternative with a "$wrapped()" would be significantly more complex with the existing building blocks. Hooking into zend_exeute_ex would allow you to implement around handling, but at this point is not recommended anymore, because its incompatible with JIT and might be removed in the future.
I would certainly describe it as a Frankenstein monster (due to my lack of core experience), but it proves it is possible in an extension. I wasn't able to figure out overriding the method - it looks like that might be possible by messing with the zend_function object but that would certainly run into issues with jit.

Thread (15 messages)

« previous php.internals (#113553) next »