Search code examples
phpc++php-extension

How to return $this in a php Extension?


For example this method of Dataset object returns NULL, How do I make it to return $this

PHP_METHOD(TSet, nextLine)
{
    TSet *MySet;
    tset_object *obj = (tset_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
    MySet = obj->DataSet;
    if (MySet != NULL) {
        MySet->nextLine();
    }
    RETURN_NULL();
}

Tried

zval *object = getThis();
RETURN_ZVAL(object,false,false);

Gave me segfault
And just to be sure also this

RETURN_ZVAL(getThis(),false,false);

With same result


Solution

  • RETURN_ZVAL(getThis(), 1, 0);

    Is the correct answer, not sure why though.
    Got it from http://www.snailinaturtleneck.com/blog/2011/08/11/php-extensions-made-eldrich-classes/#comment-466980122