我如何 return 来自 php 扩展的数组?
How do i return an array from php extension?
如何从 php 扩展方法 return 数组?这是我目前所拥有的:
struct myClass_object
{
zend_object std;
MyClass *myClassInstance;
};
PHP_METHOD(MyClass, getMyArray)
{
zval *obj = getThis();
MyClass *myClass = (myClass_object *) zend_object_store_get_object (obj TRMLS_CC)->myClassInstance;
if (myClass != NULL)
{
int length = myClass->getMyArrayLength();
int *myArray = myClass->getMyArray();
// return myArray!
}
RETURN_NULL();
}
在检查了一些 php 源文件后,我能够 return 一个像这样的数组:
PHP_METHOD(MyClass, getMyArray)
{
zval *obj = getThis();
MyClass *myClass = (myClass_object *) zend_object_store_get_object (obj TRMLS_CC)->myClassInstance;
if (myClass != NULL)
{
int length = myClass->getMyArrayLength();
int *myArray = myClass->getMyArray();
array_init(return_value);
for (int i = 0; i < length; i++) add_index_long(return_value, i, myArray[i]);
return;
}
RETURN_NULL();
}
如何从 php 扩展方法 return 数组?这是我目前所拥有的:
struct myClass_object
{
zend_object std;
MyClass *myClassInstance;
};
PHP_METHOD(MyClass, getMyArray)
{
zval *obj = getThis();
MyClass *myClass = (myClass_object *) zend_object_store_get_object (obj TRMLS_CC)->myClassInstance;
if (myClass != NULL)
{
int length = myClass->getMyArrayLength();
int *myArray = myClass->getMyArray();
// return myArray!
}
RETURN_NULL();
}
在检查了一些 php 源文件后,我能够 return 一个像这样的数组:
PHP_METHOD(MyClass, getMyArray)
{
zval *obj = getThis();
MyClass *myClass = (myClass_object *) zend_object_store_get_object (obj TRMLS_CC)->myClassInstance;
if (myClass != NULL)
{
int length = myClass->getMyArrayLength();
int *myArray = myClass->getMyArray();
array_init(return_value);
for (int i = 0; i < length; i++) add_index_long(return_value, i, myArray[i]);
return;
}
RETURN_NULL();
}