• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

CopernicaMarketingSoftware/PHP-CPP-LEGACY: The PHP-CPP library for PHP 5.*

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

CopernicaMarketingSoftware/PHP-CPP-LEGACY

开源软件地址:

https://github.com/CopernicaMarketingSoftware/PHP-CPP-LEGACY

开源编程语言:

C++ 98.3%

开源软件介绍:

PHP-CPP-LEGACY

The PHP-CPP-LEGACY library is a fork of the PHP-CPP library that can be used for old PHP5 deployments. If you no longer use PHP 5.*, we recommend using the master PHP-CPP library instead.

The PHP-CPP and PHP-CPP-LEGACY library have an almost identical API. This means that you can easily port C++ extensions that you wrote for PHP5 to PHP7 (and the other way around).

ABOUT

PHP-CPP-LEGACY is created and maintained by Copernica (www.copernica.com). We write our code mostly in PHP and C++ and needed an effective way to combine these two languages. That's where PHP-CPP comes in. Do you appreciate our work and are you looking for other high quality solutions?

Then check out our other solutions:

The power of PHP-CPP

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_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);

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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap