void INIT_CLASS_ENTRY(zend_class_entry ce, char *classname, zend_function_entry *functions); void INIT_OVERLOADED_CLASS_ENTRY(zend_class_entry ce, char *classname, zend_function_entry *functions, zend_function *handle_fcall, zend_function *handle_propget, zend_function *handle_propset); void INIT_OVERLOADED_CLASS_ENTRY_EX(zend_class_entry ce, char *classname, zend_function_entry *functions, zend_function *handle_fcall, zend_function *handle_propget, zend_function *handle_propset, zend_function *handle_propunset, zend_function *handle_propisset);
This triplet of macros initializes a zend_class_entry structure using the properties given. Note that although ce is passed as an immediate value, these are macro structures and thus can and do modify the calling value.
Argument |
Purpose |
---|---|
ce |
A temporary storage unit for holding initialization values. When zend_register_internal_class() is called later, this value will no longer be relevant. |
classname |
NULL-terminated character string containing the userspace visible name of the class. |
functions |
A NULL-terminated vector of zend_function_entry elements as used with zend_module_entry structures. |
handle_fcall |
Series of "magic methods" corresponding to __call(), __get(), __set(), __unset(), and __isset() respectively. |
void zend_class_implements(zend_class_entry *ce TSRMLS_DC, int num_interfaces, ...);
Marks a class as implementing one or more interfaces.
Argument |
Purpose |
---|---|
ce |
Class entry implementing the interfaces listed |
num_interfaces |
The number of interfaces that follow, passed as zend_class_entry* |
... |
num_interfaces instances of zend_class_entry* pointers |
zend_class_entry *zend_register_internal_class( zend_class_entry *ce TSRMLS_DC); zend_class_entry *zend_register_internal_class_ex(zend_class_entry *ce, zend_class_entry *parent_ce, char *parent_name TSRMLS_DC); zend_class_entry *zend_register_internal_interface( zend_class_entry *ce TSRMLS_DC);
Registers a zend_class_entry previously initialized using the INIT_CLASS_ENTRY family of macros. The _ex variant of this method allows for inheritance at time of registration.
Argument |
Purpose |
---|---|
ce |
The previously initialized class entry being registered |
parent_ce |
The already registered class entry of this class's parent |
parent_name |
Name of the parent class used in error reporting should parent_ce->name be unavailable |
int zend_lookup_class(char *name, int name_len, zend_class_entry ***ppce TSRMLS_DC); int zend_lookup_class_ex(char *name, int name_len, int use_autoload, zend_class_entry ***ppce TSRMLS_DC); zend_class_entry *zend_fetch_class(char * name, uint name_len, int fetch_type TSRMLS_DC);
Locates a class entry by name. zend_fetch_class() returns the class entry directly, whereas the other two methods return a zend_class_entry** container by reference.
Argument |
Purpose |
---|---|
name |
NULL-terminated name of class to look for. Does not need to be lowercased prior to calling this function. |
name_len |
Length of class name excluding the trailing NULL. |
use_autoload |
Set to nonzero if the __autoload() mechanism should be used. |
ppce |
Pointer to a zend_class_entry** variable to store the class definition in. |
Properties
int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *value, int access_type TSRMLS_DC); int zend_declare_property_ex(zend_class_entry *ce, char *name, int name_length, zval *value, int access_type, char *doc_comment, int doc_comment_len TSRMLS_DC); int zend_declare_property_null(zend_class_entry *ce, char *name, int name_length, int access_type TSRMLS_DC); int zend_declare_property_bool(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC); int zend_declare_property_long(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC); int zend_declare_property_double(zend_class_entry *ce, char *name, int name_length, double value, int access_type TSRMLS_DC); int zend_declare_property_string(zend_class_entry *ce, char *name, int name_length, char *value, int access_type TSRMLS_DC); int zend_declare_property_stringl(zend_class_entry *ce, char *name, int name_length, char *value, int value_len, int access_type TSRMLS_DC);
Declares a default property for a class definition. These methods should be called during class declaration time (such as the MINIT phase).
Argument |
Purpose |
---|---|
ce |
The zend_class_entry* being modified. |
name |
NULL-terminated property name. |
name_length |
Length of property name excluding the trailing NULL byte. |
value |
Type-specific valuedepends on method being used. Note that when declaring a property from a zval, the zval must be persistently allocated. |
value_len |
Unique to the stringl variant of these methods; specifies the length of the string pointed to by value excluding the trailing NULL. |
access_type |
One of ZEND_ACC_PUBLIC, ZEND_ACC_PROTECTED, or ZEND_ACC_PRIVATE. To declare a static property rather than a standard one, combine the value of ZEND_ACC_STATIC using a bitwise OR. |
int zend_declare_class_constant(zend_class_entry *ce, char *name, size_t name_length, zval *value TSRMLS_DC); int zend_declare_class_constant_long(zend_class_entry *ce, char *name, size_t name_length, long value TSRMLS_DC); int zend_declare_class_constant_bool(zend_class_entry *ce, char *name, size_t name_length, zend_bool value TSRMLS_DC); int zend_declare_class_constant_double(zend_class_entry *ce, char *name, size_t name_length, double value TSRMLS_DC); int zend_declare_class_constant_string(zend_class_entry *ce, char *name, size_t name_length, char *value TSRMLS_DC); int zend_declare_class_constant_stringl(zend_class_entry *ce, char *name, size_t name_length, char *value, size_t value_len TSRMLS_DC);
Declares a class constant for ce with the provided name and value.
Argument |
Purpose |
---|---|
ce |
The zend_class_entry* being modified. |
name |
NULL-terminated constant name. |
name_length |
Length of property name excluding the trailing NULL byte. |
value |
Type-specific valuedepends on method being used. Note that when declaring a property from a zval, the zval must be persistently allocated. |
value_len |
Unique to the stringl variant of these methods, specifies the length of the string pointed to by value excluding the trailing NULL. |
void zend_update_property(zend_class_entry *scope, zval *object, char *name, int name_length, zval *value TSRMLS_DC); void zend_update_property_null(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC); void zend_update_property_bool(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC); void zend_update_property_long(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC); void zend_update_property_double(zend_class_entry *scope, zval *object, char *name, int name_length, double value TSRMLS_DC); void zend_update_property_string(zend_class_entry *scope, zval *object, char *name, int name_length, char *value TSRMLS_DC); void zend_update_property_stringl(zend_class_entry *scope, zval *object, char *name, int name_length, char *value, int value_len TSRMLS_DC); int zend_update_static_property(zend_class_entry *scope, char *name, int name_length, zval *value TSRMLS_DC); int zend_update_static_property_null(zend_class_entry *scope, char *name, int name_length TSRMLS_DC); int zend_update_static_property_bool(zend_class_entry *scope, char *name, int name_length, long value TSRMLS_DC); int zend_update_static_property_long(zend_class_entry *scope, char *name, int name_length, long value TSRMLS_DC); int zend_update_static_property_double(zend_class_entry *scope, char *name, int name_length, double value TSRMLS_DC); int zend_update_static_property_string(zend_class_entry *scope, char *name, int name_length, char *value TSRMLS_DC); int zend_update_static_property_stringl(zend_class_entry *scope, char *name, int name_length, char *value, int value_len TSRMLS_DC);
Sets a standard or static property of an instantiated object. The nonstatic methods invoke the write_property handler enabling the consistent use of overloading.
Argument |
Purpose |
---|---|
scope |
Active scope at the time of method call to enforce PPP (Public/Protected/Private) restrictions. |
object |
When updating a nonstatic property, this refers to the instance being updated. |
name |
NULL-terminated property name. |
name_length |
Length of property name excluding the trailing NULL byte. |
value |
Type-specific valuedepends on method being used. |
value_len |
Unique to the stringl variant of these methods; specifies the length of the string pointed to by value excluding the trailing NULL. |
zval *zend_read_property(zend_class_entry *scope, zval *object, char *name, int name_length, zend_bool silent TSRMLS_DC); zval *zend_read_static_property(zend_class_entry *scope, char *name, int name_length, zend_bool silent TSRMLS_DC);
Reads a property from a given class or object instance. The nonstatic version invokes the object's read_property handler to allow proper handling of overloaded objects.
Argument |
Purpose |
---|---|
scope |
Active scope at the time of method call to enforce PPP (Public/Protected/Private) restrictions. |
object |
When fetching a nonstatic property, this refers to the instance being updated. |
name |
NULL-terminated property name. |
name_length |
Length of property name excluding the trailing NULL byte. |
silent |
When set to a nonzero value, no "undefined property" errors will be reported. Note: Instances with no read_property handler defined will report an error regardless of the silent argument. |
int add_property_long_ex(zval *object, char *key, uint key_len, long l TSRMLS_DC); int add_property_null_ex(zval *object, char *key, uint key_len TSRMLS_DC); int add_property_bool_ex(zval *object, char *key, uint key_len, int value TSRMLS_DC); int add_property_resource_ex(zval *object, char *key, uint key_len, long value TSRMLS_DC); int add_property_double_ex(zval *object, char *key, uint key_len, double value TSRMLS_DC); int add_property_string_ex(zval *object, char *key, uint key_len, char *str, int dup TSRMLS_DC); int add_property_stringl_ex(zval *object, char *key, uint key_len, char *value, uint value_len, int dup TSRMLS_DC); int add_property_zval_ex(zval *object, char *key, uint key_len, zval *value TSRMLS_DC);
Adds a property to an instantiated object.
Argument |
Purpose |
---|---|
object |
Object instance being updated. |
key |
Either an ordinary NULL-terminated string (for public properties), or a specially formatted string as returned by zend_mangle_property_name(). |
ken_len |
Length of key including the trailing NULL byte. Note: A non-_ex version of these functions also exists that excludes the last NULL from this length parameter. |
value |
Type-specific valuedepends on method being used. |
value_len |
Unique to the stringl variant of these methods; specifies the length of the string pointed to by value excluding the trailing NULL. |
dup |
Set to 0 if the string is in an emalloc'd buffer that can be given to the engine. Set to nonzero to force duplication of the string. |
void zend_mangle_property_name(char **dest, int *dest_len, char *scope, int scope_len, char *propname, int propname_len, int internal);
Encodes a property name with scope visibility information.
Argument |
Purpose |
---|---|
dest |
Populated by reference with newly allocated memory containing mangled property name. |
dest_len |
Length of mangled property name including the trailing NULL byte. |
scope |
To encode the property name for PRIVATE access, specify the NULL-terminated name of the "owning" class here. PROTECTED properties should use a scope of *. PUBLIC properties should not use this function. |
scope_len |
Length of scope string excluding the trailing NULL byte. For example, PROTECTED scope will always have a length of 1. |
propname |
NULL-terminated name of actual property as it will appear in userspace. |
propname_len |
Length of property name excluding the trailing NULL. |
internal |
When set to 0, per-request memory allocation will be used; otherwise, persistent allocation will be performed. Either way, it is the calling scope's responsibility to free this memory. |
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