Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72222 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69042 invoked from network); 4 Feb 2014 22:46:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2014 22:46:03 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.50 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.215.50 mail-la0-f50.google.com Received: from [209.85.215.50] ([209.85.215.50:55556] helo=mail-la0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 19/37-13782-9AD61F25 for ; Tue, 04 Feb 2014 17:46:02 -0500 Received: by mail-la0-f50.google.com with SMTP id ec20so7127764lab.9 for ; Tue, 04 Feb 2014 14:45:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:message-id:subject:to:content-type; bh=xz1M3zzHMdXNNp3ILUuLHdaRrR3rqd1nPCOcfCVrHio=; b=noWvrrJb33+RETmaXB7GL+JDgft7Y5p2IHeeL1Vz2P+pA8y+XQ3Z9c86KYUyCDmBxF j6owoUF/eNjDY9H27h1uN5DZ6aR/hRgp4TQGboV6dhxU7sJ68Jn3f//kWhDp9JEcv/dg lBy2+JJEVEawDOURC95F/t3usYWkv18qNrkIIXpBw3Aq8/AUODOHDvGTOlcG5RUlfb3I sAvJcpF4JNF03lg8lIb9yP/jpRHm/HyJjJixPRMq3ExVMBgABULIB7X4whbbh435f0zO EJHkx39lMvdeDd1y9w8q8qfsc0udvR8rw68Pls5WXDX19cYCc5TygZZ+a8/ZUDK0FAMj V+3w== X-Received: by 10.112.138.233 with SMTP id qt9mr7510821lbb.34.1391553958234; Tue, 04 Feb 2014 14:45:58 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.199.37 with HTTP; Tue, 4 Feb 2014 14:45:18 -0800 (PST) Date: Wed, 5 Feb 2014 07:45:18 +0900 X-Google-Sender-Auth: qdFFY_vOYTK99WiQKqwWLQmhHFI Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=089e012297105dd37904f19c678b Subject: Another idea for declare - pre/post call hooks From: yohgaki@ohgaki.net (Yasuo Ohgaki) --089e012297105dd37904f19c678b Content-Type: text/plain; charset=UTF-8 Hi all, I've posted this in "Declare minimum PHP version required?" thread. I thought it my be better to have new thread for this. On Mon, Feb 3, 2014 at 3:58 PM, Yasuo Ohgaki wrote: > I thought it might be good for us to have declaring minimum PHP version > required to execute script. > http://jp1.php.net/manual/en/control-structures.declare.php > I have concluded that these checks should be done by new assert() https://wiki.php.net/rfc/expectations I think of another idea for declare(). Current declare() has 'tick'. How about have hooks 'pre_hook' and 'post_hook'? It works like tick. Tick executes registered function/code by execution cycle. 'pre_hook' and 'post_hook' executes registered function/code before function call and after function call. Something like declare(pre_hook=TYPE) { some_useful_code } declare(post_hook=TYPE) { some_useful_code } Where TYPE is 0=none, 1=user, 2=internal, 3=both. 'none' is for to use hook inside function body. These hooks are executed like function foo() { // pre_hook hook here some useful code // post_hook hook here (executed for all 'return') } This is useful for user land PHP debugger/profiler as well as pre/post condition checks. We have dbg, but it's nice to have hook in user land for simple debugging and profiling also. It may be convenient if hooked functions/methods can be specified, but it might be headache with namespace. Simply hooking all calls might be simpler as it does not have to be fast. Or declare() may be used inside functions. function foo() { declare(pre_hook=0) { some useful code } declare(post_hook=0) { some useful code } body } There are many way for hook design. Just an another idea for declare(). Since declare() is compiler directive, INI is needed for enabling/disabling for all files. Any comments for this feature? -- Yasuo Ohgaki yohgaki@ohgaki.net --089e012297105dd37904f19c678b--