Liite E. Extending PHP

Sisällys
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

Esimerkki 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.

Variable Function Arguments

Esimerkki E-2 .






Using the Function Arguments

Taulu E-1 .










Memory Management in Functions

Setting Variables in the Symbol Table



Varoitus

Esimerkki E-3 .




Esimerkki 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.

Esimerkki E-5 .




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

Esimerkki 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.












Returning simple values





Returning complex values

  1. 
    
    
    










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.

Esimerkki E-7 .




Esimerkki E-8 .




Esimerkki 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).

Using the persistent resource table





Adding runtime configuration directives