Beschreibe hier die neue Seite. |
==== PHP Module ==== 1.) gerüst erstellen [[Code] ext_skel --extname=<modulename> ] 2.) config.m4 editieren .. es sind Zeilen ausgeklammert welche aber UNBEDINGT da sein müssen wenn's jemals ein lauffähiges Library werden soll! === Funktionen definieren === in php_test.h === Returnoptionen === Array "auffädeln", mittels [[Code] add_assoc_string(return_value,"hashelement",stringcomment,1) add_assoc_long(return_value,"hashelement",longval) add_assoc_double(return_value,"hashelement",doubleval); ] === phpinfo() informationen === {PHP MINFO FUNCTION}?(devinfo){php_info_print_table_start(); php_info_print_table_row(2, "DevArticles? Extension", "All Systems Go"); und in der devarticlesmod_module_entry welche sicherlich irgendwo php übergeben wird [[Code] /* include standard header */ /* you will need to include this in all of your php extension projects*/ #include "php.h" /* All the functions that will be exported (available) must be declared */ {ZEND FUNCTION}?(hello_world); {PHP MINFO FUNCTION}?(devarticlesmod); /* Just a basic int to be used as a counter*/ int i; /* function list so that the Zend engine will know what’s here */ zend_function_entry devarticlesmod_functions[] = { {ZEND FE}?(hello_world, NULL) {NULL, NULL, NULL} }; /* module information */ zend_module_entry devarticlesmod_module_entry = { {STANDARD MODULE HEADER}?, "DevArticles?", devarticlesmod_functions, NULL, NULL, NULL, NULL, {PHP MINFO}?(devarticlesmod), {NO VERSION YET}?, {STANDARD MODULE PROPERTIES}? }; #if {COMPILE DL DEVARTICLES MOD}? {ZEND GET MODULE}?(devarticlesmod) #endif {PHP MINFO FUNCTION}?(devarticlesmod) { php_info_print_table_start(); php_info_print_table_row(2, "DevArticles? Extension", "All Systems Go"); php_info_print_table_end(); } {ZEND FUNCTION}?(hello_world) { for(i=0;i<5;i++) { zend_printf("Hello World "); } } ] === returnarray === [[Code] Arrays Arrays are stored using Zend's internal hash tables, which can be accessed using the zend_hash_*() API. For every array that you want to create, you need a new hash table handle, which will be stored in the ht member of the zval.value container. There's a whole API solely for the creation of arrays, which is extremely handy. To start a new array, you call array_init(). zval *new_array; {MAKE STD ZVAL}?(new_array); if(array_init(new_array) != SUCCESS) { // do error handling here } If array_init() fails to create a new array, it returns FAILURE. To add new elements to the array, you can use numerous functions, depending on what you want to do. Tabelle 33-1, Tabelle 33-2 and Tabelle 33-3 describe these functions. All functions return FAILURE on failure and SUCCESS on success. Tabelle 33-1. Zend's API for Associative Arrays Function Description add_assoc_long(zval *array, char *key, long n);() Adds an element of type long. add_assoc_unset(zval *array, char *key);() Adds an unset element. add_assoc_bool(zval *array, char *key, int b);() Adds a Boolean element. add_assoc_resource(zval *array, char *key, int r);() Adds a resource to the array. add_assoc_double(zval *array, char *key, double d);() Adds a floating-point value. add_assoc_string(zval *array, char *key, char *str, int duplicate);() Adds a string to the array. The flag duplicate specifies whether the string contents have to be copied to Zend internal memory. add_assoc_stringl(zval *array, char *key, char *str, uint length, int duplicate); () Adds a string with the desired length length to the array. Otherwise, behaves like add_assoc_string(). Tabelle 33-2. Zend's API for Indexed Arrays, Part 1 Function Description add_index_long(zval *array, uint idx, long n);() Adds an element of type long. add_index_unset(zval *array, uint idx);() Adds an unset element. add_index_bool(zval *array, uint idx, int b);() Adds a Boolean element. add_index_resource(zval *array, uint idx, int r);() Adds a resource to the array. add_index_double(zval *array, uint idx, double d);() Adds a floating-point value. add_index_string(zval *array, uint idx, char *str, int duplicate);() Adds a string to the array. The flag duplicate specifies whether the string contents have to be copied to Zend internal memory. add_index_stringl(zval *array, uint idx, char *str, uint length, int duplicate);() Adds a string with the desired length length to the array. This function is faster and binary-safe. Otherwise, behaves like add_index_string()(). Tabelle 33-3. Zend's API for Indexed Arrays, Part 2 Function Description add_next_index_long(zval *array, long n);() Adds an element of type long. add_next_index_unset(zval *array);() Adds an unset element. add_next_index_bool(zval *array, int b);() Adds a Boolean element. add_next_index_resource(zval *array, int r);() Adds a resource to the array. add_next_index_double(zval *array, double d);() Adds a floating-point value. add_next_index_string(zval *array, char *str, int duplicate);() Adds a string to the array. The flag duplicate specifies whether the string contents have to be copied to Zend internal memory. add_next_index_stringl(zval *array, char *str, uint length, int duplicate);() Adds a string with the desired length length to the array. This function is faster and binary-safe. Otherwise, behaves like add_index_string()(). All these functions provide a handy abstraction to Zend's internal hash API. Of course, you can also use the hash functions directly - for example, if you already have a zval container allocated that you want to insert into an array. This is done using zend_hash_update()() for associative arrays (see Beispiel 33-3) and zend_hash_index_update() for indexed arrays (see Beispiel 33-4): Beispiel 33-3. Adding an element to an associative array. zval *new_array, *new_element; char *key = "element_key"; {MAKE STD ZVAL}?(new_array); {MAKE STD ZVAL}?(new_element); if(array_init(new_array) == FAILURE) { // do error handling here } {ZVAL LONG}?(new_element, 10); if(zend_hash_update(new_array->value.ht, key, strlen(key) + 1, (void *)&new_element, sizeof(zval *), NULL) == FAILURE) { // do error handling here } Beispiel 33-4. Adding an element to an indexed array. zval *new_array, *new_element; int key = 2; {MAKE STD ZVAL}?(new_array); {MAKE STD ZVAL}?(new_element); if(array_init(new_array) == FAILURE) { // do error handling here } {ZVAL LONG}?(new_element, 10); if(zend_hash_index_update(new_array->value.ht, key, (void *)&new_element, sizeof(zval *), NULL) == FAILURE) { // do error handling here } To emulate the functionality of add_next_index_*(), you can use this: zend_hash_next_index_insert(ht, zval **new_element, sizeof(zval *), NULL) ] Note: To return arrays from a function, use array_init() and all following actions on the predefined variable return_value (given as argument to your exported function; see the earlier discussion of the call interface). You do not have to use {MAKE STD ZVAL}? on this. Tip: To avoid having to write new_array->value.ht every time, you can use {HASH OF}?(new_array), which is also recommended for compatibility and style reasons. Booleans === Links === * ![]() |
PHP Module | ![]() |
1.) gerüst erstellen
![]() |
|
2.) config.m4 editieren .. es sind Zeilen ausgeklammert welche aber UNBEDINGT da sein müssen wenn's jemals ein lauffähiges Library werden soll!
Funktionen definieren | ![]() |
in php_test.h
Returnoptionen | ![]() |
Array "auffädeln", mittels
![]() |
|
phpinfo() informationen | ![]() |
{PHP MINFO FUNCTION}?(devinfo){php_info_print_table_start(); php_info_print_table_row(2, "DevArticles? Extension", "All Systems Go");
und in der devarticlesmod_module_entry welche sicherlich irgendwo php übergeben wird
![]() |
|
returnarray | ![]() |
![]() |
|
Tip: To avoid having to write new_array->value.ht every time, you can use {HASH OF}?(new_array), which is also recommended for compatibility and style reasons. Booleans
Links | ![]() |