It is possible to fetch the zend resources (zend_fetch_resource
) without knowing the type of the fetching resource? If so, how?
Note: I am writing PHP extension.
It is possible to fetch the zend resources (zend_fetch_resource
) without knowing the type of the fetching resource? If so, how?
Note: I am writing PHP extension.
Yes, you can.
zend_fetch_resource
won't work because it receives the the types of resources that are acceptable and fails if the found one is not one of those.
Just use
void *zend_list_find(int id, int *type);
From the resource zval you can extract the id with Z_RESVAL(zval)
. The argument type
will be filled with the type of the resource found.
However, I don't see much usage for this, except maybe to create a var_dump
clone. The problem is that once you retrieve an arbitrary resource, what are you going to do with it?... In general, you know nothing about the returned data structure.
You can get the name of the resource directly with:
char *zend_rsrc_list_get_rsrc_type(int resource TSRMLS_DC);