__toString() must return a string value

From: Date: Sat, 21 Feb 2009 12:15:55 +0000
Subject: __toString() must return a string value
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-6140@lists.php.net to get a copy of this message
Hi! Method implementation looks like this (for DateTime derived): static PHP_METHOD(midgard_datetime, __toString) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) return; /* Prepare DateTime::format argument */ zval *fmt; MAKE_STD_ZVAL(fmt); ZVAL_STRING(fmt, "c", 0); /* Invoke Datetime::format */ zval *zend_object = getThis(); zend_call_method_with_1_params(&zend_object, Z_OBJCE_P(zend_object), NULL, "format", &return_value, fmt); } Now PHP code: $dt = new midgard_datetime(); echo $dt; triggers: Catchable fatal error: Method midgard_datetime::__toString() must return a string value It will work, if I change implementation a bit: zval *strv = NULL; zend_call_method_with_1_params(&zend_object, Z_OBJCE_P(zend_object), NULL, "format", &strv, fmt); RETURN_STRING(Z_STRVAL_P(strv), 0); Is there some special convention (not) to use predefined return_value? Piotras

« previous php.pecl.dev (#6140) next »