Re: __toString() must return a string value

From: Date: Sat, 21 Feb 2009 19:02:16 +0000
Subject: Re: __toString() must return a string value
References: 1 2  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-6142@lists.php.net to get a copy of this message
Johannes Schlüter writes: > On Sat, 2009-02-21 at 13:15 +0100, Piotr Pokora wrote: >> Hi! Hi! >> zend_call_method_with_1_params(&zend_object, >> Z_OBJCE_P(zend_object), NULL, "format", &return_value, fmt); > > here you are passing the address of your local variable "return_value" > so zend_call_method will change the pointer. It's basically like doing > > return_value = 23; return_value is predefined variable of type zval, so what it's the difference? Looks like it's common practice to implement code like: object_init_ex(return_value, ce); array_init(return_value); Isn't it? > [...] >> 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); > > When doing this you should check they type. You might also use > RETURN_ZVAL() if you don't care for the type. Why? Isn't it DateTime::format responsible to set string? Besides... RETURN_STRING will copy strv to return_value. And, am I really responsible to set type of zval when passing it as in/out function argument? Again. Is there common convention to (not) use return_value? Piotras

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