Giter Club home page Giter Club logo

php-cpp's Introduction

PHP-CPP

The PHP-CPP library is a C++ library for developing PHP extensions. It offers a collection of well documented and easy-to-use classes that can be used and extended to build native extensions for PHP. The full documentation can be found on http://www.php-cpp.com.

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. In fact, the only thing you need to do is write a function in C++, and 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_word()
{
    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);

Working with parameters and return values is just as easy:

Php::Value my_plus(Php::Parameters &params)
{
    return params[0] + params[1];
}

The method call to export the above C++ function:

extension.add("my_plus", my_plus, {
	Php::ByVal("a", Php::numericType),
	Php::ByVal("b", Php::numericType)
});

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.

Type conversion between native C/C++ types and PHP variables is handled by PHP-CPP, using features from the C++11 language. It does not matter if your functions accept strings, integers, booleans or other native parameters: PHP-CPP takes care of the conversion. The return value of your function is also transformed by PHP-CPP into PHP.

More complicated structured can be handled by PHP-CPP as well. If you would like to return a nested associative array from your function, you can do so too:

Php::Value get_complex_array()
{
    Php::Value r;
    r["a"] = 123;
    r["b"] = 456;
    r["c"][0] = "nested value";
    r["c"][1] = "example";
    return r;
}

The C++ function above is equivalent to the following function in PHP:

function get_complex_array()
{
    return array(
        "a" => 123,
        "b" => 456,
        "c" => array("nested_value","example")
    );
}

More information and more examples are available on the official website: http://www.php-cpp.com.

php-cpp's People

Contributors

emielbruijntjes avatar jaspervaneck avatar valmat avatar semeleer avatar lisachenko avatar guweigang avatar rwoverdijk avatar jgmdev avatar

Watchers

Alvar Laigna avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.