Returning Values

Table of contents:

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

The PHP Life Cycle

Variables from the Inside Out

Memory Management

Setting Up a Build Environment

Your First Extension

Returning Values

Accepting Parameters

Working with Arrays and HashTables

The Resource Data Type

PHP4 Objects

PHP5 Objects

Startup, Shutdown, and a Few Points in Between

INI Settings

Accessing Streams

Implementing Streams

Diverting the Stream

Configuration and Linking

Extension Generators

Setting Up a Host Environment

Advanced Embedding

Appendix A. A Zend API Reference

Appendix B. PHPAPI

Appendix C. Extending and Embedding Cookbook

Appendix D. Additional Resources



Extending and Embedding PHP
Extending and Embedding PHP
ISBN: 067232704X
EAN: 2147483647
Year: 2007
Pages: 175
Authors: Sara Golemon

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net