如何使用 PHP-CPP 在 PHP 类中添加静态数组

how to add an static array in php class with php-cpp

本文关键字:添加 静态 数组 PHP 何使用 PHP-CPP      更新时间:2023-10-16

我想添加一个静态成员,如下所示

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

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

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

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