Returning Values
USERSPACE FUNCTIONS MAKE USE OF THE return keyword to pass information back to their calling scope in the same manner that you're probably familiar with doing in a C
application, for example:
function sample_long() { return 42; } $bar = sample_long();
When sample_long() is called, the number 42 is returned and populated into the $bar variable. In C this might be done using a nearly identical code base:
int sample_long(void) { return 42; } void main(void) { int bar = sample_long(); }
Of course, in C you always know what the function being called is going to return based on its function prototype so you can declare the variable the result will be stored in accordingly. When dealing with PHP userspace, however, the variable type is dynamic and you have to fall back on the zval type introduced in Chapter 2, "Variables from the Inside Out."
The return_value Variable
|