I found a note on this site which was very helpful in converting a PHP5 extension to PHP7. I seem to be stuck on another issue.
I have a function in a C extension that looks like this
PHP_FUNCTION(GetSystemInformation)
{
struct dsiDeviceIdParams deviceParams[WS_MAX_STACKABLE_UNITS];
zval avar[WS_MAX_STACKABLE_UNITS];
int num, ret, i;
zval *adeviceParams;
zval *znumberOfElementsInList;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/z/",
&adeviceParams, &znumberOfElementsInList) == FAILURE)
{
return;
}
ret = dsiGetSystemInformation(deviceParams, &num);
if (WS_OK != ret)
{
RETURN_LONG(ret);
// i added these and the "a/z/" flags
zval_dtor(znumberOfElementsInList);
zval_dtor(adeviceParams); // i tried moving this to the end of the function too
znumberOfElementsInList->value.lval = num; // this value works! i can see it back on the webpage PHP
array_init(adeviceParams);
if (num > WS_MAX_STACKABLE_UNITS)
{
num = WS_MAX_STACKABLE_UNITS;
}
if (num > 0 && num <= WS_MAX_STACKABLE_UNITS)
{
for (i = 0; i < num; ++i)
{
//MAKE_STD_ZVAL(avar[i]);
array_init(&avar[i]);
sprintf(txt,"d1 %s
",deviceParams[i].boxNumber); dump(txt);
add_assoc_long_ex(&avar[i], "boxNumber", sizeof("boxNumber"),
deviceParams[i].boxNumber);
sprintf(txt,"d2 %s
",deviceParams[i].modelNumber); dump(txt);
local_add_assoc_string_ex(&avar[i], "modelNumber", sizeof("modelNumber"),
deviceParams[i].modelNumber, 1);
sprintf(txt,"d3 %s
",deviceParams[i].versionNumber); dump(txt);
local_add_assoc_string_ex(&avar[i], "versionNumber", sizeof("versionNumber"),
deviceParams[i].versionNumber, 1);
sprintf(txt,"d4 %s
",deviceParams[i].serialNumber); dump(txt);
local_add_assoc_string_ex(&avar[i], "serialNumber", sizeof("serialNumber"),
deviceParams[i].serialNumber, 1);
sprintf(txt,"d5 %d
",deviceParams[i].numberOfPorts); dump(txt);
add_assoc_long_ex(&avar[i], "numberOfPorts", sizeof("numberOfPorts"),
deviceParams[i].numberOfPorts);
dump("D6
");
add_next_index_zval(adeviceParams, &avar[i]);
dump("DE
");
}
}
RETURN_LONG(ret);
}
it is called in PHP like this
I get the value back properly for NumberOfElements. However, The deviceParams value is null/empty and it doesn't seem to be able to find any of the array fields
A PHP Error was encountered Severity: Notice Message: Undefined index: modelNumber Filename: controllers/login.php Line Number: 158
If i run this line
debug_zval_dump( $deviceParams );
I can see the content (i.e model number/etc).
array(1) refcount(2){ [0]=> array(5) refcount(1){ ["boxNumber"]=> int(0) ["modelNumber"]=> string(9) "VS-1224-F" refcount(1) ["versionNumber"]=> string(12) "1.4.20160607" refcount(1) ["serialNumber"]=> string(8) "15090500" refcount(1) ["numberOfPorts"]=> int(24) } }
I am sure this has something to do with reference pointers/etc and am not yet sure how to resolve this. Can someone point me in the right direction?
Basically, I want to pass an array into my C extension, change the contents of the array (mostly populating it), and then see the contents back at the PHP level for presentation in the webpage. I can get all the way through except the presentation part.