# how is a return values stored?

- Thread: https://externals.io/message/25834
- Original archive: https://news-web.php.net/php.internals/25834
- Started by Prometheus Prometheus on 2006-09-26T11:32:21+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

---

## #25834 — Prometheus Prometheus — 2006-09-26T11:32:21+00:00

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

hiho@ll

i was just asking myself, if it is possible, to get the return value of a 
function after the function calls "return" (or throws an exception) and 
before the value is returned

example:
class A{
     public function __construct(){}
     public function __destruct(){
       // here i want the return value like:
       $retval = idontknowwhichfunction();
       print $retval; // this print's "test"
     }
}

function B(){
   $classvar = new A();

   return "test";
}

i thought it would be a very impressive function for that purpose
for what i would need it:
think about testing a big php application
calling hundreds of functions and debugging them takes very long
but if i could track the arguments (debug_back_trace() function) AND the 
return values (that's what i'm asking for) i could run a complete test and 
after this i could change the input values automated and compare it with the 
output i got before

another option for this, would be just debugging of such applications
cause it can be boring to debug big applications and with such a possibility 
i can reproduce the problem very fast and at any point within my application

the question is:
Q1: how is the return value (return or throw) stored within php?
      or another question would be: is it possible to write an extension 
which can retrieve every variable set within my php session? (i know of the 
security problems this produces, but until know, i'm evaluating if it can 
work) and would be the return value within this variables?
any hint on this would be great!
since it's possible to create a sandbox within php (runkit extension) i 
think it should be possible to get the return value (or exception object) 
before the calling function receives it, not?
Q2: maybe i didn't find it, but is there a finished php function which i can 
use like debug_back_trace but for the return value?
Q3: anybody has another idea for such a "testing" or debugging environment?
      the main advantage of such a system would be: i can start debugging 
from any point within my code and i could very easily create automated 
test's which can compare the result (what it is and what it should be) 
"automated"

thx@ll

---

## #25836 — Matt Sicker — 2006-09-26T16:02:53+00:00

URL: https://externals.io/message/25834#25836 · In reply to: #25834

> hiho@ll
>
> i was just asking myself, if it is possible, to get the return value
> of a function after the function calls "return" (or throws an
> exception) and before the value is returned
>
> example:
> class A{
>      public function __construct(){}
>      public function __destruct(){
>        // here i want the return value like:
>        $retval = idontknowwhichfunction();
>        print $retval; // this print's "test"
>      }
> }
>
> function B(){
>    $classvar = new A();
>
>    return "test";
> }
>
> i thought it would be a very impressive function for that purpose
> for what i would need it:
> think about testing a big php application
> calling hundreds of functions and debugging them takes very long
> but if i could track the arguments (debug_back_trace() function) AND
> the return values (that's what i'm asking for) i could run a complete
> test and after this i could change the input values automated and
> compare it with the output i got before
>
> another option for this, would be just debugging of such applications
> cause it can be boring to debug big applications and with such a
> possibility i can reproduce the problem very fast and at any point
> within my application
>
> the question is:
> Q1: how is the return value (return or throw) stored within php?
>       or another question would be: is it possible to write an
> extension which can retrieve every variable set within my php
> session? (i know of the security problems this produces, but until
> know, i'm evaluating if it can work) and would be the return value
> within this variables?
> any hint on this would be great!
> since it's possible to create a sandbox within php (runkit extension)
> i think it should be possible to get the return value (or exception
> object) before the calling function receives it, not?
> Q2: maybe i didn't find it, but is there a finished php function
> which i can use like debug_back_trace but for the return value?
> Q3: anybody has another idea for such a "testing" or debugging
> environment? the main advantage of such a system would be: i can
> start debugging from any point within my code and i could very easily
> create automated test's which can compare the result (what it is and
> what it should be) "automated"
>
> thx@ll
Oh sweet, something I know!

Return values are stored in zval *return_value.  That's within any 
function that follows the Zend format (i.e. ZEND_FUNCTION() macro to 
declare it, returns value via the RETURN_*() macros).
-- 
Matt Sicker

---

## #25837 — Derick Rethans — 2006-09-26T16:16:46+00:00

URL: https://externals.io/message/25834#25837 · In reply to: #25834

> i was just asking myself, if it is possible, to get the return value of a
> function after the function calls "return" (or throws an exception) and before
> the value is returned

Only through an extension.

> i thought it would be a very impressive function for that purpose
> for what i would need it:
> think about testing a big php application
> calling hundreds of functions and debugging them takes very long
> but if i could track the arguments (debug_back_trace() function) AND the
> return values (that's what i'm asking for) i could run a complete test and
> after this i could change the input values automated and compare it with the
> output i got before

Xdebug (http://xdebug.org) does this with trace files storing both 
function/method name, parameters and return values to a file on disk. 
See: http://xdebug.org/docs-settings.php#auto_trace (and the 3 settings 
after it in the docs)

> the question is:
> Q1: how is the return value (return or throw) stored within php?
>      or another question would be: is it possible to write an extension which
> can retrieve every variable set within my php session? (i know of the security
> problems this produces, but until know, i'm evaluating if it can work) and
> would be the return value within this variables?
> any hint on this would be great!
> since it's possible to create a sandbox within php (runkit extension) i think
> it should be possible to get the return value (or exception object) before the
> calling function receives it, not?

Yes, this is possible with an extension. You would need to reimplement 
the zend_execute function. Again, you can find on how to do that in the 
Xdebug sources.

> Q2: maybe i didn't find it, but is there a finished php function which i can
> use like debug_back_trace but for the return value?

There is none.

regards,
Derick
