Re: __toString() must return a string value
| From: | Piotr Pokora | Date: | Sun, 22 Feb 2009 08:19:16 +0000 |
| Subject: | Re: __toString() must return a string value | ||
| References: | 1 2 3 4 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-6144@lists.php.net to get a copy of this message | ||
Johannes Schlüter writes:
Hi!
>> Why? Isn't it DateTime::format responsible to set string?
>
> It might return a NULL-zval in case it has problems passing the
> parameter or in case of another error.
What might return NULL zval?
PHP_FUNCTION(date_format)
{
[...]
RETURN_STRING(date_format(format, format_len, dateobj->time,
dateobj->time->is_localtime), 0);
}
Can you give me a pointer where this method(function) returns NULL zval
so I should really worry about in derived class? Of course, you are
right, to avoid future segfaults when API change I should return zval.
But, I started this thread to talk about this particular case.
>> And, am I really responsible to set type of zval when passing it as
>> in/out function argument?
>
> Yes.
Can you explain why it works when I pass 'strv' initialized as NULL?
Besides, isn't it very bad to initialize zval variable without knowing
what method or function will do with it?
OK, let's assume I initialize this zval with some zend type. Which one?
Array, long, bool, object maybe?
> Probably you should fetch a C book and e-read the chapter about
> pointers.
I do not think I have problems with C or understanding what pointer is
or not.
I started a thread @pecl, because I have problems understanding zend
API, and I have been told it's the best place to talk about it.
Zend/zend.h:#define INTERNAL_FUNCTION_PARAMETERS int ht, zval
*return_value, zval **return_value_ptr, zval *this_ptr, int
return_value_used TSRMLS_DC
Isn't return_value a pointer?
So what's the difference between zval *strv and zval *return_value ?
Can you be so kind and suggest a solution (part of code or source file
which uses it) to use return_value instead of duplicating 'strv' to
return_value?
Should it looks like this?
MAKE_STD_ZVAL(return_value);
Z_TYPE_P(return_value) = IS_STRING;
zend_call_method_with_1_params(&zend_object,
Z_OBJCE_P(zend_object), NULL, "format", &return_value, fmt);
From spl extension:
zval *rv;
zend_call_method_with_1_params(&object, Z_OBJCE_P(object),
&intern->fptr_offset_get, "offsetGet", &rv, offset);
Clearly, rv is a pointer and not initialized as particular zend type.
Piotras