Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113553 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99451 invoked from network); 16 Mar 2021 01:44:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Mar 2021 01:44:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7F7FA1804B8 for ; Mon, 15 Mar 2021 18:38:02 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 15 Mar 2021 18:37:58 -0700 (PDT) Received: by mail-qt1-f175.google.com with SMTP id u7so10613448qtq.12 for ; Mon, 15 Mar 2021 18:37:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=0HDtvWU+ex9sS2jruco4gAmWowAe1iHOfXC3g5/+eqY=; b=Tjmy/AA/eovSlsbZix20DuZbOeycLQr34CkfLEVua+rzL/Y4TL3bcHkaz4Ob/xBuwB hv/qynVK8Q/n2+b7jXWvmGX23tJK9PfTtHKKWMXpL9NB0kao5vGGLePpwKFmUobAsi4t bPU7KX9w7GaDE7nZCci5asUF13Fplqc5Phmb0DzOxBu08mFUniOfOYly++sAXK/N3tr2 DK46aEK6vAWXnHM1ieWaYzt0YBBZXnaLaSU9e98NfEWXMUleUqy5tH7LnsqbhlGnr12e PLWAIGEUUkrt67jSkbWVL3B7i03sfK5hi8B9Gp5Etp54bv1+vxOLuVN2J4NjTUYUWMib OWug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=0HDtvWU+ex9sS2jruco4gAmWowAe1iHOfXC3g5/+eqY=; b=lRHJqa1rg3hlDryA8/0VXQW6cfKlTcDf5FTvNg4CevNTssHzD4PLtd1j2OfeF3AyO9 RXfBcW2BRa3ADMkkt50QdIYuWDpTa5CgJv2Q6rv3j5B4y62wa1O5f1VGgF1jR7at5H3i 3PHYfUvVrizZR+e8X7KYKZRfWBVbqlpeMHojcPmL/4w85ZaZtPz75uHXiv8RPLKP1m/F QnAXNUe3557bnivrLclkDeaFd/e1p9LyakhTKbi/iEW5L8obUb6Hz76v2ta2NnwB5K3s mxzaTzW8s3rghN3xE0hqAO2MxnDNsWIICOovyVTXpZzsEGfctfgSPjDURcI7e0T6Fcf5 p0wQ== X-Gm-Message-State: AOAM5327gF+7e6git5KywvARBnbPy4NCltvUGoOAtU5uVdwtFY4OuVRi vSe3khHGBGsOJihPdKYT/yxwzl1ppN+N X-Google-Smtp-Source: ABdhPJxtWPqOoeKt619VZiROZj3puBhcyiX6+h9E6Nx2B4QyNwLiHt8H7f/slLMMPO6l4Yd0ytj6Vw== X-Received: by 2002:ac8:5313:: with SMTP id t19mr25218304qtn.148.1615858674641; Mon, 15 Mar 2021 18:37:54 -0700 (PDT) Received: from ?IPv6:2603:7081:150f:9506:7143:2375:4a57:de6c? (2603-7081-150f-9506-7143-2375-4a57-de6c.res6.spectrum.com. [2603:7081:150f:9506:7143:2375:4a57:de6c]) by smtp.gmail.com with ESMTPSA id z6sm12257065qtv.69.2021.03.15.18.37.53 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Mar 2021 18:37:54 -0700 (PDT) To: internals@lists.php.net References: Message-ID: <363bed3b-04ac-b8b2-aa30-2e1df49436e3@gmail.com> Date: Mon, 15 Mar 2021 21:37:50 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Subject: Re: [PHP-DEV] Built-in decorator attribute? From: iggyvolz@gmail.com (Katie Volz) 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.