I am creating an SPI extension for my Raspberry Pi, and have encountered a rather strange problem with a class function that I am trying to add. (The repo is here if you want to check anything obvious I am missing: php_spi on Github)
In my php_spi.h I have defined:
PHP_METHOD(Spi, blockTransfer);
#if (PHP_MAJOR_VERSION >= 5)
ZEND_BEGIN_ARG_INFO_EX(Spi__blockTransfer_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
#if (PHP_MINOR_VERSION > 0)
ZEND_ARG_ARRAY_INFO(0, data, 1)
#else
ZEND_ARG_INFO(0, data)
#endif
ZEND_ARG_INFO(0, colDelay)
ZEND_ARG_INFO(0, discard)
ZEND_END_ARG_INFO()
#else /* PHP 4.x */
#define Spi__blockTransfer_args NULL
#endif
This is along with a few other methods, similarly defined that currently work. In my spi.c file I have the function defined as follows:
/* {{{ proto array blockTransfer(array data[, int colDelay[, bool discard]])
*/
PHP_METHOD(Spi, blockTransfer)
{
zend_class_entry * _this_ce;
zval * _this_zval = NULL;
zval * data = NULL;
HashTable * data_hash = NULL;
long colDelay = 1;
zend_bool discard = 0;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "a|lb", &_this_zval, Spi_ce_ptr, &data, &colDelay, &discard) == FAILURE) {
return;
}
_this_ce = Z_OBJCE_P(_this_zval);
// some code
}
/* }}} blockTransfer */
And I have made sure that my function has an entry in the function list:
static zend_function_entry Spi_methods[] = {
PHP_ME(Spi, __construct, Spi____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(Spi, __destruct, Spi____destruct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
PHP_ME(Spi, transfer, Spi__transfer_args, /**/ZEND_ACC_PUBLIC)
PHP_ME(Spi, blockTransfer, Spi__blockTransfer_args, /**/ZEND_ACC_PUBLIC)
PHP_ME(Spi, getInfo, Spi__getInfo_args, /**/ZEND_ACC_PUBLIC)
PHP_ME(Spi, setupTimer, Spi__setupTimer_args, /**/ZEND_ACC_PUBLIC)
PHP_ME(Spi, usecDelay, Spi__usecDelay_args, /**/ZEND_ACC_PUBLIC)
{ NULL, NULL, NULL }
};
The code compiles cleanly, with no errors or warnings, but when I try to test the function I get a PHP error saying that the function is not defined. What could I possibly be missing?
(Just to be clear, this is a working extension except for this one function)
EDIT: Thank you for the downvote on a question that is older than one year.
Well, that was a stunning about of time wasted on a typo in my test file :o(
I should have read the error more carefully as it was about the function blockTransfer() being undefined, not the method.
In the test file I had:
$read = $spi-blockTransfer();
Doh!
Sorry for wasting your time.