05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

There are three basic flavors of array-insertion functions: inserting at a specific<br />

numeric index, inserting at the next numeric index, and inserting at a specific string<br />

index. These flavors exist for all data types.<br />

Inserting at a specific numeric index ($arg[$idx] = $value) looks like this:<br />

add_index_long(zval *arg, uint idx, long n)<br />

add_index_null(zval *arg, uint idx)<br />

add_index_bool(zval *arg, uint idx, int b)<br />

add_index_resource(zval *arg, uint idx, int r)<br />

add_index_double(zval *arg, uint idx, double d)<br />

add_index_string(zval *arg, uint idx, char *str, int duplicate)<br />

add_index_stringl(zval *arg, uint idx, char *str, uint length, int duplicate)<br />

add_index_zval(zval *arg, uint index, zval *value)<br />

Inserting at the next numeric index ($arg[] = $value) looks like this:<br />

add_next_index_long(zval *arg, long n)<br />

add_next_index_null(zval *arg)<br />

add_next_index_bool(zval *, int b)<br />

add_next_index_resource(zval *arg, int r)<br />

add_next_index_double(zval *arg, double d)<br />

add_next_index_string(zval *arg, char *str, int duplicate)<br />

add_next_index_stringl(zval *arg, char *str, uint length, int duplicate)<br />

add_next_index_zval(zval *arg, zval *value)<br />

And inserting at a specific string index ($arg[$key] = $value) looks like this:<br />

add_assoc_long(zval *arg, char *key, long n)<br />

add_assoc_null(zval *arg, char *key)<br />

add_assoc_bool(zval *arg, char *key, int b)<br />

add_assoc_resource(zval *arg, char *key, int r)<br />

add_assoc_double(zval *arg, char *key, double d)<br />

add_assoc_string(zval *arg, char *key, char *str, int duplicate)<br />

add_assoc_stringl(zval *arg, char *key, char *str, uint length, int duplicate)<br />

add_assoc_zval(zval *arg, char *key, zval *value)<br />

Objects<br />

Returning an object requires you to define the object first. Defining an object from C<br />

involves creating a variable corresponding to that class and building an array of functions<br />

for each of the methods. The MINIT( ) function for your extension should register<br />

the class.<br />

The following code defines a class and returns an object:<br />

static zend_class_entry *my_class_entry_ptr;<br />

static zend_function_entry php_my_class_functions[] = {<br />

<strong>PHP</strong>_FE(add, NULL)<br />

<strong>PHP</strong>_FALIAS(del, my_del, NULL)<br />

<strong>PHP</strong>_FALIAS(list, my_list, NULL)<br />

340 | Chapter 14: Extending <strong>PHP</strong><br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!