custom handler for specific zend_ops

From: Date: Tue, 27 Feb 2007 22:03:28 +0000
Subject: custom handler for specific zend_ops
Groups: php.internals 
Request: Send a blank email to internals+get-28174@lists.php.net to get a copy of this message
Hi all. [Please, let me know if there is a better place to ask such questions.] In a Zend extension I'm working on, I need to perform some actions when certain instructions (zend_ops) are executed by the VM. Note that I'm interesting in specific instructions rather than instruction types, e.g., the first echo zend_op of a function as opposed to all echo instructions. Also, I want the handler to be invoked only when an interesting statement is executed (in other words, determining whether a zend_op is interesting must be done before execution). The way I currently do that is as follows: I override the zend_compile_file function to retrieve the zend_op_array of a file, identify the interesting statements in the array, and override their handler (the handler field in the zend_op struct) with my custom handler: The custom handler looks like this: int custom_handler(ZEND_OPCODE_HANDLE_ARGS) {
     // do my stuff
     ....
     return zend_vm_get_opcode_handler(execute_data->opline->opcode,
        execute_data->opline)(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
} where zend_get_opcode_handler is a copy-and-paste of the static function in zend_vm_execute.h While this seems to work (on the limited tests I've run) it also looks too hackish to be the correct way to do this ;-) So, here's the question: is there a better way to achieve the same result? I've looked at the USER_OPCODE API, but it seems to me that the API doesn't allow to specify a handler for specific zend_ops (but let me know if I'm wrong!) Thanks in advance, Marco

« previous php.internals (#28174) next »