# Question on return_value

- Thread: https://externals.io/message/19866
- Original archive: https://news-web.php.net/php.internals/19866
- Started by Bob Silva on 2005-11-01T06:47:45+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #19866 — Bob Silva — 2005-11-01T06:47:45+00:00

URL: https://externals.io/message/19866#19866

Hi,

 

I have an internal function defined that returns an array zval:

 

zval *pow_zstring_internal_split(Z_STRVAL_P(ivalue), separator, count, 0
TSRMLS_DC);

 

 

 

When I call it like this,  return_value is `NULL` in userland.

return_value = pow_zstring_internal_split(Z_STRVAL_P(ivalue), separator,
count, 0 TSRMLS_CC);

 

 

But when I call it like this, it works as expected and an array is returned
to userland

array = pow_zstring_internal_split(Z_STRVAL_P(ivalue), separator, count, 0
TSRMLS_CC);

*return_value = *array;

 

 

I'm sure there is an obvious answer, but given my background (or lack
thereof) in C, I can't figure it out.

How does the temporary assignment change things inside the engine?

 

Bob

---

## #19879 — Michael Wallner — 2005-11-01T09:29:21+00:00

URL: https://externals.io/message/19866#19879 · In reply to: #19866

Bob Silva wrote:
> Hi,
> 
> I have an internal function defined that returns an array zval:
> zval *pow_zstring_internal_split(Z_STRVAL_P(ivalue), separator, count, 0
> TSRMLS_DC);
>  
> 
> When I call it like this,  return_value is `NULL` in userland.
> 
> return_value = pow_zstring_internal_split(Z_STRVAL_P(ivalue), separator,
> count, 0 TSRMLS_CC);

The outta world doesn't care if you let return_value point else where in
your function.  Look up the chapter pointers in your book. Short version:
You need a pointer to a pointer so that the caller gets another pointer.

> But when I call it like this, it works as expected and an array is returned
> to userland
> 
> array = pow_zstring_internal_split(Z_STRVAL_P(ivalue), separator, count, 0
> TSRMLS_CC);
> 
> *return_value = *array;

Yes, because you change the members of the struct the pointer points at and
the pointer is still the same of that of the "outta world".

> I'm sure there is an obvious answer, but given my background (or lack
> thereof) in C, I can't figure it out.
> 
> How does the temporary assignment change things inside the engine?

Hä? :)

Regards,
-- 
Michael - <mike(@)php.net> http://dev.iworks.at/ext-http/http-functions.html.gz

---

## #19880 — Marcus Boerger — 2005-11-01T09:48:10+00:00

URL: https://externals.io/message/19866#19880 · In reply to: #19866

Hello Bob,

  look at RETURN_ZVAL() again.

Tuesday, November 1, 2005, 7:47:45 AM, you wrote:

> Hi,

>  

> I have an internal function defined that returns an array zval:

>  

> zval *pow_zstring_internal_split(Z_STRVAL_P(ivalue), separator, count, 0
> TSRMLS_DC);

>  

>  

>  

> When I call it like this,  return_value is `NULL` in userland.

> return_value = pow_zstring_internal_split(Z_STRVAL_P(ivalue), separator,
> count, 0 TSRMLS_CC);

>  

>  

> But when I call it like this, it works as expected and an array is returned
> to userland

> array = pow_zstring_internal_split(Z_STRVAL_P(ivalue), separator, count, 0
> TSRMLS_CC);

> *return_value = *array;

>  

>  

> I'm sure there is an obvious answer, but given my background (or lack
> thereof) in C, I can't figure it out.

> How does the temporary assignment change things inside the engine?

>  

> Bob




Best regards,
 Marcus
