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

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,

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,

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
postedFeb 27, '07 at 10:03p
activeFeb 27, '07 at 10:03p

1 user in discussion

Marco Cova: 1 post



site design / logo © 2022 Grokbase