In SaxonC PHP extension (written in C++) I am writing utility to allow users to write custom functions in their PHP script which will get called in XSLT, XPath or XQuery. Therefore we have to handle a number of PHP native return types from the user function. This I can do without problem, except for ArrayIterators. We get back a zval
which can be an ArrayIterator. But how can I check if it is actually an ArrayIterator type in the PHP internals using the Zend framework written in C++ code?
See the coe snippet below:
zval retval;
int value = (int)Z_TYPE_P(&retval)
The value gives zero (i.e. IS_UNDEF) when I know its should be an ArrayIterator and not IS_OBJECT. How can I check for ArrayIterator?
2
Answers
spl_ce_ArrayIterator
is declared inspl_array.h
You probably should check for
Traversable
objects in general usinginstanceof_function(Z_OBJCE_P(data), zend_ce_traversable)
.If the type of the
retval
isIS_UNDEF
after calling a user function, this means the function threw an exception.Aside: you can just use
Z_TYPE(retval)
instead ofZ_TYPE_P(&retval)