【问题标题】:how to add an static array in php class with php-cpp如何使用 php-cpp 在 php 类中添加静态数组
【发布时间】:2017-08-15 08:12:48
【问题描述】:

我想添加一个像下面这样的静态成员

class BaseYii{
    public static $map = [1,2,3]//sutff
}

这是我的 C++ 代码,

class BaseYii : public Php::Base {
public:
Php::Array  hehe;

BaseYii() = default;

/**
 *  c++ destructor
 */
virtual ~BaseYii() = default;

void __construct() {
    Php::Value self(this);
    Php::Array x{123, "adf"};
    self["fff"] = x;
}

void getServer() {
    Php::call("var_dump", Php::SERVER);
}
};

注册扩展,如何设置一个 Php::Array 或 Php::value 到这个属性

Php::Class<BaseYii> baseYii("BaseYii");

Php::Class<Yii> Yii("Yii");
static std::map<int, int> map;
map[1] = 1;
baseYii.property("classMap", "here ,i want to set a Array or Php::value", Php::Public | Php::Static);

【问题讨论】:

    标签: php c++ php-cpp


    【解决方案1】:

    Zend API 不支持这一点——默认属性值不能是数组、对象或资源。

    http://lxr.php.net/source/xref/PHP-7.0/Zend/zend_API.c

    https://github.com/CopernicaMarketingSoftware/PHP-CPP/issues/277

    【讨论】:

      猜你喜欢
      • 2019-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多