Objects

Since objects can be converted to arrays (and vice versa), you might have already guessed that they have a lot of similarities to arrays in PHP. Objects are maintained with the same hash functions, but there's a different API for creating them.

To initialize an object, you use the function object_init():

zval *new_object;

MAKE_STD_ZVAL(new_object);

if(object_init(new_object) != SUCCESS)
{
    // do error handling here
}

You can use the functions described in Table 9.11 to add members to your object.

Note: All functions in Table 9.11 work on the object object with the key key. The key forms the member name, so the resulting member can be accessed via $object->key.

Table 9.11. Zend's API for Object Creation
FunctionDescription
add_property_long ...

Get Web Application Development with PHP 4.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.