PHP Ext API
关于本函数列表
为了帮助php开发者更方便的开发扩展,这里整理了一份ZEND API的函数列表,由于本人能力有限,这些并不是全部,我打算在git上开个项目,来撰写这些API的使用范例,如果你对这个项目感兴趣,并想贡献一份力量,请发email给我yangrokety@gmail.com
已在git上立项:PHP ZEND API
输出相关 About Output
php_printf(format, var)
PHPWRITE(string, strlen(string))
spprintf(char **, max, format, var...)
:使用该函数前必须先分配好第一个参数的内存空间snprintf(char *, length, format, var...)
:会动态地为第一个参数分配内存
上述3、4函数详细讨论:Difference between sprintf, snprintf and spprintf
参数相关 About Parameters
int zend_parse_parameters(int num_args TSRMLS_DC, char *type_spec, ...)
函数负责读取用户从参数堆栈传递来参数,并将其适当地转换后放入局部C语言变量。如果用户传递的参数个数有误或类型不可被转换,函数会发出一个冗长的错误信息,并返回FAILURE。
第一个参数应该为ZEND_NUM_ARGS()
。
类型说明符和变量存储结构:
|
:在该符号之前的参数都是可选的
/
:在该字符之前的变量如果不是通过引用传递,那么对其进行ZVAL分离,即执行SEPARATE_ZVAL_IF_NOT_REF()
!
:在该字符之后的变量可以为特定的类型或者NULL(对于上图中的说明符,除了’b’,’l’,’d’都适用),如果传递了NULL,那么指针将会指向NULL
具体参数解析例子,可以查看PHP源代码phpsrc/README.PARAMETER_PARSING_API
返回值相关 About Return Values
RETURN_NULL()
RETURN_BOOL(b)
b: 0 => FALSE, non-0 => TRUERETURN_TRUE
RETURN_FALSE
RETURN_LONG(l)
l: Integer valueRETURN_DOUBLE(d)
d: Floating point valueRETURN_STRING(str, dup)
str: char* string value dup: 0/1 flag, duplicate string?RETURN_STRINGL(str, len, dup)
len: Predetermined string lengthRETURN_EMPTY_STRING()
数组相关 Aobut Array
关联数组 Associate Array:
int add_assoc_long(zval *arg, char *key, long n)
add_assoc_null(zval *arg, char *key)
add_assoc_bool(zval *arg, char *key, int b)
add_assoc_resource(zval *arg, char *key, int r)
add_assoc_double(zval *arg, char *key, double d)
add_assoc_string(zval *arg, char *key, char *str, int dup)
int add_assoc_stringl(zval *arg, char *key, char *str, uint len, int dup);
int add_assoc_zval(zval *arg, char *key, zval *value)
索引数组 Index Array:
int add_index_long(zval *arg, ulong idx, long n)
int add_index_null(zval *arg, ulong idx)
int add_index_bool(zval *arg, ulong idx, int b)
int add_index_resource(zval *arg, ulong idx, int r)
int add_index_double(zval *arg, ulong idx, double d)
int add_index_string(zval *arg, ulong idx, const char *str, int duplicate)
int add_index_stringl(zval *arg, ulong idx, const char *str, uint length, int duplicate)
int add_index_zval(zval *arg, ulong index, zval *value)
int add_next_index_long(zval *arg, long n)
int add_next_index_null(zval *arg)
int add_next_index_bool(zval *arg, int b)
int add_next_index_resource(zval *arg, int r)
int add_next_index_double(zval *arg, double d)
int add_next_index_string(zval *arg, const char *str, int duplicate)
int add_next_index_stringl(zval *arg, const char *str, uint length, int duplicate)
int add_next_index_zval(zval *arg, zval *value)
Hash Table
startup/shutdown:
int zend_hash_init(HashTable *ht,uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, zend_bool persistent);
void zend_hash_destroy(HashTable *ht)
void zend_hash_clean(HashTable *ht)
Removes all elements from the HashTable
additions/updates/changes:
int zend_hash_update(HashTable *ht, const char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest)
int zend_hash_add(HashTable *ht, const char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest)
ulong zend_get_hash_value(char *arKey, uint nKeyLength)
int zend_hash_num_elements(HashTable *ht)
count($ht)int zend_hash_quick_add(HashTable *ht, const char *arKey, uint nKeyLength, ulong h, void *pData, uint nDataSize, void **pDest)
int zend_hash_quick_update(HashTable *ht, const char *arKey, uint nKeyLength, ulong h, void *pData, uint nDataSize, void **pDest)
int zend_hash_index_update(HashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest)
int zend_hash_next_index_insert(HashTable *ht, void *pData, uint nDataSize, void **pDest)
int zend_hash_add_empty_element(HashTable *ht, const char *arKey, uint nKeyLength);
void zend_hash_graceful_destroy(HashTable *ht)
void zend_hash_graceful_reverse_destroy(HashTable *ht)
void zend_hash_apply(HashTable *ht, apply_func_t apply_func TSRMLS_DC)
void zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void * TSRMLS_DC)
void zend_hash_apply_with_arguments(HashTable *ht TSRMLS_DC, apply_func_args_t apply_func, int, ...)
void zend_hash_reverse_apply(HashTable *ht, apply_func_t apply_func TSRMLS_DC);
Deletes:
int zend_hash_del(HashTable *ht, const char *arKey, uint nKeyLength)
int zend_hash_quick_del(HashTable *ht, const char *arKey, uint nKeyLength, ulong h)
zend_hash_index_del(HashTable *ht, ulong h)
Data retreival:
int zend_hash_find(const HashTable *ht, const char *arKey, uint nKeyLength, void **pData)
int zend_hash_index_find(const HashTable *ht, ulong h, void **pData)
int zend_hash_quick_find(const HashTable *ht, const char *arKey, uint nKeyLength, ulong h, void **pData);
Misc:
int zend_hash_exists(const HashTable *ht, const char *arKey, uint nKeyLength)
int zend_hash_quick_exists(const HashTable *ht, const char *arKey, uint nKeyLength, ulong h)
int zend_hash_index_exists(const HashTable *ht, ulong h)
ulong zend_hash_next_free_element(const HashTable *ht)
traversing:
int zend_hash_has_more_elements(ht)
int zend_hash_move_forward(ht)
int zend_hash_move_backwards(ht)
int zend_hash_get_current_key(ht, str_index, num_index, duplicate)
int zend_hash_get_current_key_type(ht)
int zend_hash_get_current_data(ht, pData)
void zend_hash_internal_pointer_reset(ht)
void zend_hash_internal_pointer_end(ht)
int zend_hash_update_current_key(ht, key_type, str_index, str_length, num_index)
Copying, merging and sorting:
void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size)
- ` void _zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, int overwrite ZEND_FILE_LINE_DC)`
void zend_hash_merge_ex(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, uint size, merge_checker_func_t pMergeSource, void *pParam)
int zend_hash_sort(HashTable *ht, sort_func_t sort_func, compare_func_t compare_func, int renumber TSRMLS_DC)
int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t compar, zend_bool ordered TSRMLS_DC)
int zend_hash_minmax(const HashTable *ht, compare_func_t compar, int flag, void **pData TSRMLS_DC);
debug:
void zend_hash_display_pListTail(const HashTable *ht)
void zend_hash_display(const HashTable *ht)
About Zval
accessing a zval:
(zval).value.lval Z_LVAL(zval)
((zend_bool)(zval).value.lval) Z_BVAL(zval)
(zval).value.dval Z_DVAL(zval)
(zval).value.str.val Z_STRVAL(zval)
(zval).value.str.len Z_STRLEN(zval)
(zval).value.ht Z_ARRVAL(zval)
(zval).value.obj Z_OBJVAL(zval)
Z_OBJVAL(zval).handle Z_OBJ_HANDLE(zval)
Z_OBJVAL(zval).handlers Z_OBJ_HT(zval)
zend_class_entry* Z_OBJCE(zval)
HashTable* Z_OBJPROP(zval)
Z_OBJ_HT((zval))->hf Z_OBJ_HANDLER(zval, hf)
(zval).value.lval Z_RESVAL(zval)
Z_OBJDEBUG(zval,is_tmp)
(zval).type Z_TYPE(zval)
Z_*_P(zval_p)
1-15重复一遍 相当于Z_*(*zval)
Z_*_PP(zval_pp)
1-15重复一遍 相当于Z_*(**zval)
reference count and is-ref:
Z_REFCOUNT(z)
Retrieve reference countZ_SET_REFCOUNT(z, rc)
Set reference count to rcZ_ADDREF(z)
Increment reference countZ_DELREF(z)
Decrement reference countZ_ISREF(z)
Whether zval is a referenceZ_SET_ISREF(z)
Makes zval a reference variableZ_UNSET_ISREF(z)
Resets the is-reference flagZ_SET_ISREF_TO(z, isref)
Make zval a reference is isref != 0Z_*_P(zval_p)
1-8重复一遍 相当于Z_*(*zval)
Z_*_PP(zval_pp)
1-8重复一遍 相当于Z_*(**zval)
setting types and values:
ZVAL_RESOURCE(z, l)
ZVAL_BOOL(z, b)
ZVAL_NULL(z)
ZVAL_LONG(z, l)
ZVAL_DOUBLE(z, d)
ZVAL_STRING(z, s, duplicate)
ZVAL_STRINGL(z, s, l, duplicate)
ZVAL_EMPTY_STRING(z)
ZVAL_ZVAL(z, zv, copy, dtor)
allocate and initialize a zval:
INIT_PZVAL(zp)
Set reference count and isref 0INIT_ZVAL(z)
Initialize and set NULL, no pointerALLOC_INIT_ZVAL(zp)
Allocate and initialize a zvalMAKE_STD_ZVAL(zv)
Allocate, initialize and set NULLPZVAL_IS_REF(z)
ZVAL_COPY_VALUE(z, v)
ZVAL_COPY_VALUE(z, v)
INIT_PZVAL_COPY(z, v)
SEPARATE_ZVAL(ppzv)
SEPARATE_ZVAL_IF_NOT_REF(ppzv)
SEPARATE_ZVAL_TO_MAKE_IS_REF(ppzv)
COPY_PZVAL_TO_ZVAL(zv, pzv)
MAKE_COPY_ZVAL(ppzv, pzv)
REPLACE_ZVAL_VALUE(ppzv_dest, pzv_src, copy)
SEPARATE_ARG_IF_REF(varptr)
READY_TO_DESTROY(zv)
内存分配相关 About Memory Allocation
viod* emalloc(size_t size)
void* ecalloc(size_t nmemb, size_t size)
void* erealloc(void *ptr, size_t size)
void* estrdup(char *str)
void* estrndup(char *str, size_t len)
void efree(void *ptr)
void *safe_emalloc(size_t nmemb, size_t size, size_t adtl)
void *STR_EMPTY_ALLOC(void)
void* pemalloc(size_t size, int persist)
void* pecalloc(size_t nmemb, size_t size, int persist)
void* perealloc(void *ptr, size_t size, int persist)
void* pestrdup(char *str, int persist)
void pefree(void *ptr, int persist)
void* safe_pemalloc(size_t nmemb, size_t size, size_t addtl, int persist)
常量相关 About Constants
flags:
#define CONST_CS (1<<0) /* Case Sensitive */
#define CONST_PERSISTENT (1<<1) /* Persistent */
#define CONST_CT_SUBST (1<<2) /* Allow compile-time substitution */
register:
REGISTER_LONG_CONSTANT(name, lval, flags)
REGISTER_DOUBLE_CONSTANT(name, dval, flags)
REGISTER_STRING_CONSTANT(name, str, flags)
REGISTER_STRINGL_CONSTANT(name, str, len, flags)
REGISTER_NS_LONG_CONSTANT(ns, name, lval, flags)
REGISTER_NS_DOUBLE_CONSTANT(ns, name, dval, flags)
REGISTER_NS_STRING_CONSTANT(ns, name, str, flags)
REGISTER_NS_STRINGL_CONSTANT(ns, name, str, len, flags)
REGISTER_MAIN_LONG_CONSTANT(name, lval, flags)
REGISTER_MAIN_DOUBLE_CONSTANT(name, dval, flags)
REGISTER_MAIN_STRING_CONSTANT(name, str, flags)
REGISTER_MAIN_STRINGL_CONSTANT(name, str, len, flags)
int zend_register_constant(zend_constant *c TSRMLS_DC)
get:
int zend_get_constant(const char *name, uint name_len, zval *result TSRMLS_DC)
zend_constant *zend_quick_get_constant(const zend_literal *key, ulong flags TSRMLS_DC)
zend_constant *zend_quick_get_constant(const zend_literal *key, ulong flags TSRMLS_DC);
copy:
void zend_copy_constants(HashTable *target, HashTable *sourc)
void copy_zend_constant(zend_constant *c)
对象相关 About Object
init:
INIT_CLASS_ENTRY(class_container, class_name, functions)
INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset)
INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset)
INIT_NS_CLASS_ENTRY(class_container, ns, class_name, functions)
INIT_OVERLOADED_NS_CLASS_ENTRY(class_container, ns, class_name, functions, handle_fcall, handle_propget, handle_propset)
int object_init(arg)
int object_and_properties_init(arg, ce, properties)
void zend_object_std_init(zend_object *object, zend_class_entry *ce TSRMLS_DC)
zend_object_value zend_objects_new(zend_object **object, zend_class_entry *class_type TSRMLS_DC)
void zend_object_store_set_object(zval *zobject, void *object TSRMLS_DC)
void zend_object_store_ctor_failed(zval *zobject TSRMLS_DC)
zval *zend_object_create_proxy(zval *object, zval *member TSRMLS_DC)
register:
zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry TSRMLS_DC)
zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry TSRMLS_DC)
int zend_register_class_alias(name, ce)
int zend_register_ns_class_alias(ns, name, ce)
declaring class constants:
int zend_declare_class_constant(zend_class_entry *ce, const char *name, size_t name_length, zval *value TSRMLS_DC)
int zend_declare_class_constant_null(zend_class_entry *ce, const char *name, size_t name_length TSRMLS_DC)
int zend_declare_class_constant_long(zend_class_entry *ce, const char *name, size_t name_length, long value TSRMLS_DC)
int zend_declare_class_constant_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_bool value TSRMLS_DC)
int zend_declare_class_constant_double(zend_class_entry *ce, const char *name, size_t name_length, double value TSRMLS_DC)
int zend_declare_class_constant_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_length TSRMLS_DC)
int zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value TSRMLS_DC)
implements:
void zend_class_implements(zend_class_entry *class_entry TSRMLS_DC, int num_interfaces, ...)
declaring property:
- .
int zend_declare_property(zend_class_entry *ce, const char *name, int name_length, zval *property, int access_type TSRMLS_DC)
int zend_declare_property_ex(zend_class_entry *ce, const char *name, int name_length, zval *property, int access_type, const char *doc_comment, int doc comment_len TSRMLS_DC)
int zend_declare_property_null(zend_class_entry *ce, const char *name, int name_length, int access_type TSRMLS_DC)
int zend_declare_property_bool(zend_class_entry *ce, const char *name, int name_length, long value, int access_type TSRMLS_DC)
int zend_declare_property_long(zend_class_entry *ce, const char *name, int name_length, long value, int access_type TSRMLS_DC)
int zend_declare_property_double(zend_class_entry *ce, const char *name, int name_length, double value, int access_type TSRMLS_DC)
int zend_declare_property_string(zend_class_entry *ce, const char *name, int name_length, const char *value, int access_type TSRMLS_DC)
int zend_declare_property_stringl(zend_class_entry *ce, const char *name, int name_length, const char *value, int value_len, int access_type TSRMLS_DC)
update:
void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC)
void zend_update_property(zend_class_entry *scope, zval *object, const char *name, int name_length, zval *value TSRMLS_DC)
void zend_update_property_null(zend_class_entry *scope, zval *object, const char *name, int name_length TSRMLS_DC)
void zend_update_property_bool(zend_class_entry *scope, zval *object, const char *name, int name_length, long value TSRMLS_DC)
void zend_update_property_long(zend_class_entry *scope, zval *object, const char *name, int name_length, long value TSRMLS_DC)
void zend_update_property_double(zend_class_entry *scope, zval *object, const char *name, int name_length, double value TSRMLS_DC)
void zend_update_property_string(zend_class_entry *scope, zval *object, const char *name, int name_length, const char *value TSRMLS_DC)
void zend_update_property_stringl(zend_class_entry *scope, zval *object, const char *name, int name_length, const char *value, int value_length TSRMLS DC)
int zend_update_static_property(zend_class_entry *scope, const char *name, int name_length, zval *value TSRMLS_DC)
int zend_update_static_property_null(zend_class_entry *scope, const char *name, int name_length TSRMLS_DC)
int zend_update_static_property_bool(zend_class_entry *scope, const char *name, int name_length, long value TSRMLS_DC)
int zend_update_static_property_long(zend_class_entry *scope, const char *name, int name_length, long value TSRMLS_DC)
int zend_update_static_property_double(zend_class_entry *scope, const char *name, int name_length, double value TSRMLS_DC)
int zend_update_static_property_string(zend_class_entry *scope, const char *name, int name_length, const char *value TSRMLS_DC)
int zend_update_static_property_stringl(zend_class_entry *scope, const char *name, int name_length, const char *value, int value_length TSRMLS_DC)
read:
zval *zend_read_property(zend_class_entry *scope, zval *object, const char *name, int name_length, zend_bool silent TSRMLS_DC)
zval *zend_read_static_property(zend_class_entry *scope, const char *name, int name_length, zend_bool silent TSRMLS_DC)
zend_class_entry *zend_get_class_entry(const zval *zobject TSRMLS_DC)
int zend_get_object_classname(const zval *object, const char **class_name, zend_uint *class_name_len TSRMLS_DC)
char *zend_get_type_by_const(int type)
getThis()
zend_object *zend_objects_get_address(const zval *object TSRMLS_DC)
void *zend_object_store_get_object(const zval *object TSRMLS_DC)
void *zend_object_store_get_object_by_handle(zend_object_handle handle TSRMLS_DC)
copy and free:
void zend_objects_clone_members(zend_object *new_object, zend_object_value new_obj_val, zend_object *old_object, zend_object_handle handle TSRMLS_DC)
zend_object_value zend_objects_clone_obj(zval *object TSRMLS_DC)
void zend_objects_free_object_storage(zend_object *object TSRMLS_DC)
zend_object_value zend_objects_store_clone_obj(zval *object TSRMLS_DC)
destruct:
void zend_object_std_dtor(zend_object *object TSRMLS_DC)
void zend_objects_destroy_object(zend_object *object, zend_object_handle handle TSRMLS_DC)
void zend_objects_store_call_destructors(zend_objects_store *objects TSRMLS_DC)
void zend_objects_store_mark_destructed(zend_objects_store *objects TSRMLS_DC)
void zend_objects_store_destroy(zend_objects_store *objects)
void zend_objects_store_free_object_storage(zend_objects_store *objects TSRMLS_DC)
refcount and is-ref:
void zend_objects_store_add_ref(zval *object TSRMLS_DC)
void zend_objects_store_del_ref(zval *object TSRMLS_DC)
void zend_objects_store_add_ref_by_handle(zend_object_handle handle TSRMLS_DC)
zend_uint zend_objects_store_get_refcount(zval *object TSRMLS_DC)