Skip to content
moriyoshi edited this page Sep 12, 2010 · 39 revisions

Boost.PHP

Boost.PHP is a set of C++ header files that allows you to create your PHP extension in C++ without any obfuscating ZEND_* / PHP_* macros, like the glorious Boost.Python after which this is loosely designed.

A typical example that defines a couple of user-land functions add() and sub():

#include "boost/php/module.hpp"
#include "boost/php/function.hpp"

using namespace boost;

class m002_module
: public php::module,
public php::function_container {
public:
class handler
: public php::module::handler {
public:
handler(m002_module* mod)
:php::module::handler(mod) {}

int add(int a, int b) { return a + b; } int sub(int a, int b) { return a – b; } };

public:
m002_module(zend_module_entry* entry)
: php::module(entry) {
entry→functions =
defun(“add”, &handler::add).
defun(“sub”, &handler::sub);
}
};

#define BOOST_PHP_MODULE_NAME m002
#define BOOST_PHP_MODULE_CAPITALIZED_NAME M002
#define BOOST_PHP_MODULE_VERSION “0.1”
#define BOOST_PHP_MODULE_CLASS_NAME m002_module

#include “boost/php/module_def.hpp”

Requirements

  • PHP version 5.1 or later.
  • Boost version 1.34.0 or later.

(Tested with g++ 3.4, 4.1 and 4.2.)

License

This software is released under Boost Software License 1.0 .

Clone this wiki locally