Data Values

As with type, the value of zvals can be inspected using a triplet of macros. These macros also begin with Z_, and optionally end with _P or _PP depending on their degree of indirection.

For the simple scalar types, Boolean, long, and double, the macros are short and consistent: BVAL, LVAL, and DVAL.

void display_values(zval boolzv, zval *longpzv,
 zval **doubleppzv)
{
 if (Z_TYPE(boolzv) == IS_BOOL) {
 php_printf("The value of the boolean is: %s
",
 Z_BVAL(boolzv) ? "true" : "false");
 }
 if (Z_TYPE_P(longpzv) == IS_LONG) {
 php_printf("The value of the long is: %ld
",
 Z_LVAL_P(longpzv));
 }
 if (Z_TYPE_PP(doubleppzv) == IS_DOUBLE) {
 php_printf("The value of the double is: %f
",
 Z_DVAL_PP(doubleppzv));
 }
}

String variables, because they contain two attributes, have a pair of macro triplets representing the char* (STRVAL) and int (STRLEN) elements:

void display_string(zval *zstr)
{
 if (Z_TYPE_P(zstr) != IS_STRING) {
 php_printf("The wrong datatype was passed!
");
 return;
 }
 PHPWRITE(Z_STRVAL_P(zstr), Z_STRLEN_P(zstr));
}

The array data type is stored internally as a HashTable* that can be accessed using the ARRVAL triplet: Z_ARRVAL(zv), Z_ARRVAL_P(pzv), Z_ARRVAL_PP(ppzv). When looking through old code in the PHP core and PECL modules, you might encounter the HASH_OF() macro, which expects a zval*. This macro is generally the equivalent of the Z_ARRVAL_P() macro; however, its use is deprecated and should not be used with new code.

Objects represent complex internal structures and have a number of access macros: OBJ_HANDLE, which returns the handle identifier, OBJ_HT for the handler table, OBJCE for the class definition, OBJPROP for the property HashTable, and OBJ_HANDLER for manipulating a specific handler method in the OBJ_HT table. Don't worry about the meaning of these various object macros just yet; they'll be covered in detail in Chapter 10, "PHP4 Objects," and Chapter 11, "PHP5 Objects."

Within a zval, a resource data type is stored as a simple integer that can be accessed with the RESVAL tripplet. This integer is passed on to the zend_fetch_resource() function which looks up the registered resource from its numeric identifier. The resource data type will be covered in depth in Chapter 9.


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