נספח E. Extending PHP

תוכן העניינים :
Adding functions to PHP
Calling User Functions
Reporting Errors

Adding functions to PHP

Function Prototype




Even if your function doesn't take any arguments, this is how it is called.

Function Arguments

דוגמה E-1 .




NOTE: Arguments can be passed either by value or by reference. In both cases you will need to pass (pval *) to getParameters. If you want to check if the n'th parameter was sent to you by reference or not, you can use the function, ParameterPassedByReference(ht,n). It will return either 1 or 0.

Setting Variables in the Symbol Table



אזהרה

דוגמה E-3 .




דוגמה E-4 .




Arrays in PHP are implemented using the same hashtables as symbol tables. This means the two above functions can also be used to check variables inside arrays.

דוגמה E-5 .




This code declares a new array, named $foo, in the active symbol table. This array is empty.

דוגמה E-6 .




If you'd like to modify a value that you inserted to a hash, you must first retrieve it from the hash. To prevent that overhead, you can supply a pval ** to the hash add function, and it'll be updated with the pval * address of the inserted element inside the hash. If that value is NULL (like in all of the above examples) - that parameter is ignored.












Using the resource list

Typically, these functions are used for SQL drivers but they can be used for anything else; for instance, maintaining file descriptors.

דוגמה E-7 .




דוגמה E-8 .




דוגמה E-9 .




The resource types should be registered in php3_list.h, in enum list_entry_type. In addition, one should add shutdown code for any new resource type defined, in list.c's list_entry_destructor() (even if you don't have anything to do on shutdown, you must add an empty case).