05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

For example:<br />

zval **old, *new;<br />

*new = **old;<br />

zval_copy_ctor(new);<br />

Here old is a populated zval container; for example, a container passed to a function<br />

that we want to modify. Our rot13 example did this in a higher-level way, which we<br />

will explore next.<br />

Accessor Macros<br />

IA large set of macros makes it easy to access fields of a zval. For example:<br />

zval foo;<br />

char *string;<br />

/* initialize foo and string */<br />

Z_STRVAL(foo) = string;<br />

The Z_STRVAL( ) macro accesses the string field of a zval. There are accessor macros<br />

for every data type that can be stored in a zval. Because you often have pointers to<br />

zvals, and sometimes even pointers to pointers to zvals, each macro comes in three<br />

flavors, as shown in Table 14-1.<br />

Table 14-1. zval accessor macros<br />

Long Boolean Double String value String length<br />

Z_LVAL( ) Z_BVAL( ) Z_DVAL( ) Z_STRVAL( ) Z_STRLEN( )<br />

Z_LVAL_P( ) Z_BVAL_P( ) Z_DVAL_P( ) Z_STRVAL_P( ) Z_STRLEN_P( )<br />

Z_LVAL_PP( ) Z_BVAL_PP( ) Z_DVAL_PP( ) Z_STRVAL_PP( ) Z_STRLEN_PP( )<br />

HashTable Object Object properties Object class entry Resource value<br />

Z_ARRVAL( ) Z_OBJ( ) Z_OBJPROP( ) Z_OBJCE( ) Z_RESVAL( )<br />

Z_ARRVAL_P( ) Z_OBJ_P( ) Z_OBJPROP_P( ) Z_OBJCE_P( ) Z_RESVAL_P( )<br />

Z_ARRVAL_PP( ) Z_OBJ_PP( ) Z_OBJPROP_PP( ) Z_OBJCE_PP( ) Z_RESVAL_PP( )<br />

There are macros to identify the active type of a zval (or zval *, orzval **). They are<br />

Z_TYPE( ), Z_TYPE_P( ), and Z_TYPE_PP( ). The possible return values are:<br />

• IS_LONG<br />

• IS_BOOL<br />

• IS_DOUBLE<br />

• IS_STRING<br />

• IS_ARRAY<br />

• IS_OBJECT<br />

• IS_RESOURCE<br />

• IS_NULL<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

The pval/zval Data Type | 333

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!