5

使用 PHP-CPP 为 PHP 做一个小扩展时,我在 C++ 端收到一个包含对象的数组,我需要检索它的类名。对象 Php::Value 看起来没有任何方法。

与我在此扩展中的 HNI 所做的类似: https ://github.com/mcuadros/bson-hni/blob/master/src/encode.cpp#L86

4

1 回答 1

4

你是对的,在 Php::Value 对象中没有特殊的方法来确定 C++ 中的类名。因此,确定类名的最佳方法是使用 Php::call 方法在 PHP 用户空间中调用 get_class 方法:

std::string classname = Php::call("get_class", object);

其中 object 是上述数组中的对象之一。

于 2014-06-10T08:43:19.030 回答