PHP 5 Power Programming

   »    Book by Andi Gutmans, Stig Sæther Bakken, and Derick Rethans

Computer Education, Training & Tutorial Resources - ComputerEducationWorld.com
Home » Free Computer Books » PHP » PHP 5 Power Programming »

To remove a resource, you usually want to
use the following macro:
int zend_list_delete(int id)
The macro is passed the id of the resource, and returns either SUCCESS or
FAILURE. If the resource exists, prior to removing it from the Zend resource list,
it will call the registered destructor for the resource type. Therefore, in our
example, you don’t have to obtain the file pointer and fclose() it before remov-
ing the resource, but you can just go ahead and delete it.
Using this macro, we can now implement file_close(): (more…)


• • •
 

To access a resource, you need to use the fol-
lowing macro (see Table 15.6 for an explanation of its arguments):
ZEND_FETCH_RESOURCE(rsrc, rsrc_type, passed_id, default_id,
resource_type_name, resource_type); (more…)


• • •
 

Implementing
file_open() should now be easy, and it should look as follows:
PHP_FUNCTION(file_open)
{
char *filename = NULL;
char *mode = NULL;
int argc = ZEND_NUM_ARGS();
int filename_len;
int mode_len;
FILE *fp;
if (zend_parse_parameters(argc TSRMLS_CC, “ss”, &filename,
&filename_len, &mode, &mode_len) == FAILURE) {
return;
} (more…)


• • •
 

We are about to imple-
ment the file_open() function. After we open the file and receive a FILE *, we
need to register it with the resource mechanism. The main macro to achieve
this is
ZEND_REGISTER_RESOURCE(rsrc_result, rsrc_pointer, rsrc_type);
An Introduction to Writing PHP Extensions Chap. 15
See Table 15.4 for an explanation of the macro’s arguments. (more…)


• • •
 



captcha PHP Script Free PHP captcha script free php
Website Design by WebWalas.com