next up previous contents
Next: Creating PHP Arrays Up: Usage Previous: Calling functions   Contents

Passing Arguments

Passing C++ arguments into PHP in PHPEmbed works much like passing format arguments into printf. The caller must provide a format string which identifies the type of each argument to follow and then follow it with arguments matching in number and type to those specified. Table 1 below provides the argument specifiers for each C++ data type. Note that C-style strings (char *) must be null terminated and that php_array objects are passed by reference.)


Table 1: PHPEmbed argument specifiers
s char *
i int
l long
d double
b bool
a php_array *

In the following example, two strings and an integer are passed into PHP and a long is returned from the PHP builtin strncmp which behaves like the standard C function of the same name.

char *one = "test1";
int comp = 4;
long match = p.call_long("strncmp", "ssi", one, "test2", comp);

The result should be 0 (indicating a match) even through the strings are different because this code compares only the first four characters.


next up previous contents
Next: Creating PHP Arrays Up: Usage Previous: Calling functions   Contents
Andrew Bosworth 2008-03-24