A C++ library for developing PHP extensions

2014 年 8 月 21 日4340

The basics

Unlike regular PHP extensions - which are really hard to implement and require a deep knowledge of the Zend engine and pointer manipulation - extensions built with PHP-CPP are not difficult to develop at all.

Functions

The PHP-CPP library uses all the power offered by C++11 to convert the parameters and return values from your functions to/and from PHP.

Php::Value hello_world()



{



return "hello world!";



}

The function above is a native C++ function. With PHP-CPP you can export this function to PHP with only one single C++ method call.

extension.add("hello_world", hello_world);

Parameters and return values

Working with parameters and return values is
just as easy.

Php::Value my_plus(Php::Parameters &parameters)



{



return (int)parameters[0] + (int)parameters[1];



}



The PHP-CPP library ensures that the variables from PHP (which internally are complicated C structures), are automatically converted into integers, passed to your function, and that the return value of your "my_plus" function is also converted back into a PHP variable.

0 0