21.7 Fetching Resource Identifiers


You want to fetch a resource identifier and perform an action on it.

Technique

Use the ZEND_FETCH_RESOURCE() macro:

 /* Completely useless function, example only */ PHP_FUNCTION(anyfetch) {     zval **listid;     type_of_resource *handle;     YOURMODLS_FETCH();     if (ZEND_NUM_ARGS() != 1          zend_get_parameters_ex(1, &listid) == FAILURE) {         WRONG_PARAM_COUNT;     }     ZEND_FETCH_RESOURCE(handle, type_of_resource *, listid, -1,                         "type_of_resource pointer", YOURMODG(le_YOURNAME));     RETURN_LONG(anyfetch(handle)); } 

Comments

The ZEND_FETCH_RESOURCE() macro fetches the resource given by the third argument into the variable given by the first argument. It then typecasts that resource to the value given by the second argument with a resource identifier type of the sixth argument. The fourth and fifth arguments are for error-handling purposes. The fourth argument is what to return on error and the fifth argument is the name of the resource to be printed.



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net