我有一个包含静态方法的 C++ 类。
声明:
class QConfig
{
public:
static int testStatic();
};
执行:
int QConfig::testStatic()
{
return 12345;
}
我希望能够从 PHP 中使用它,如下所示:
echo QConfig::testStatic() // expected result: 12345
我试过使用:
PHP_METHOD(QConfig, testStatic)
{
QConfig *qconfig;
qconfig_object *obj = (qconfig_object *)zend_object_store_get_object(
getThis() TSRMLS_CC);
qconfig = obj->qconfig;
if (qconfig != NULL) {
RETURN_LONG(qconfig->testStatic, 1);
}
RETURN_NULL();
}
...
function_entry qconfig_methods[] = {
PHP_ME(QConfig, staticTest, NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
但这会导致构建错误:
/home/testuser/test/mytest.cc:81:9: error: invalid conversion from 'int (*)()' to 'long int' [-fpermissive]
/home/testuser/test/mytest.cc: At global scope:
/home/testuser/test/mytest.cc:122:1: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
make: *** [mytest.lo] Error 1
如何访问 C++ PHP 扩展中的静态方法?