Next: , Previous: , Up: Top   [Contents]


3 Opcode Handlers

An opcode handler is a function which executes a zend_op. The Zend API provides us with the ability to replace built-in opcode handlers with user-defined ones:

ZEND_API int
zend_set_user_opcode_handler(
    zend_uchar            opcode,
    user_opcode_handler_t handler
);

Where opcode is the instruction code to be overridden, and handler is the pointer to the user-defined handler function.

typedef int (*user_opcode_handler_t) (zend_execute_data *execute_data);

The handler function should accept execute_data pointer as argument, and returns an int indicating the execution status of the handler function, which could be one of the following values:

#define ZEND_USER_OPCODE_CONTINUE   0
#define ZEND_USER_OPCODE_RETURN     1
#define ZEND_USER_OPCODE_DISPATCH   2
#define ZEND_USER_OPCODE_ENTER      3
#define ZEND_USER_OPCODE_LEAVE      4

In most cases, we only need the two return values explained below:

Once the handler is set, it will be invoked by the Zend Engine whenever a znode_op with a corresponding instruction is about to be executed. Note that multiple calls to zend_set_user_opcode_handler replace old handlers with new ones.

To disable a user-defined opcode handler, pass NULL to the handler argument.