Hashcodes zend / php cache for functions somewhere in execution data?

edit: to be clear, I want to identify and track functions called without incurring cost and hashing ambiguity on the class string. I was hoping php would keep some internal hashes.

I'm working on an extension, and I need a reliable way to get a hash code for a specific one zend_execute_data->zend_function

, without the overhead of calling some hash function in the function name (which would cause collisions with overloaded functions anyway).

_zend_execute_data.opline has a field called "extended_value" that looks like it's being set with zend_hash_function against something in op1, but only if op2 is a constant.

if (opline->op2.op_type == IS_CONST) {
    opline->extended_value = zend_hash_func(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant) + 1);


I'm not sure what the op2 type IS_CONST means, and I'm not sure if that would be reliable or not. And I'm not sure if this hash is for defining a function or a specific instance for a class.

edit: I am assuming IS_CONST means the function is not a member of an object instance.

Anything else that can be used as a hashcode proxy for execute_data-> zend_function?


source to share

1 answer

A very simple approach is to use the pointer itself zend_function *

to index into the hash table. That is, use it (unsigned long) (uintptr_t) func

as an index.

There is one caveat with this approach: while functions / methods are usually unique zend_function *

over the lifetime of a script, there are some cases (like magic __call

) where the temporal structure is zend_function *

highlighted. In these cases, the function flag ZEND_ACC_CALL_VIA_HANDLER

will be set in the function. If you want to support these cases as well, you will have to use a separate mechanism for them.



All Articles