将PHP C++扩展从php5升级到php7
将PHP C扩展从php5升级到php7在没有怎么看明白php5 php7源码的情况下接手一份基于php5写c扩展如何接手快速升级到php7环境下也能使用呢我仅仅修改了所引用的一个php中对象处理的头文件就满足了要求扩展被编译通过运行正常。phpobj.h 文件定义版本选择#ifndef _PHP_OBJ_H_2017 #define _PHP_OBJ_H_2017 #include php_version.h #if PHP_MAJOR_VERSION 7 #include php5obj.h #else #include php7obj.h #endif #endif//_PHP_OBJ_H_2017php5obj.h 旧的#define SW_RETURN_STRINGL RETURN_STRINGL #define SW_RETVAL_STRINGL RETVAL_STRING #define SW_RETVAL_STRING RETVAL_STRING #define SW_RETURN_STRING RETURN_STRING #define SW_ZVAL_STRINGL ZVAL_STRINGL #define SW_ZVAL_STRING ZVAL_STRING #define SW_MAKE_STD_ZVAL(p) MAKE_STD_ZVAL(p) #define PZVAL_IS_REF(len) ZVAL_IS_REF(len) // Register the class entry.. #define PHP5CPP_REGISTER_CLASS(name, obj_name) / { / zend_class_entry ce; / INIT_CLASS_ENTRY(ce, obj_name, php5cpp_ ## name ##_methods); / ce.create_object php5cpp_object_new_ ## name; / php5cpp_ce_ ## name zend_register_internal_class_ex(ce, NULL, NULL TSRMLS_CC); / memcpy( php5cpp_object_handlers_ ## name, / zend_get_std_object_handlers(), / sizeof(zend_object_handlers) ); / php5cpp_object_handlers_ ## name.clone_obj NULL; / php5cpp_ce_ ## name-ce_flags | ZEND_ACC_FINAL_CLASS; / } #define PHP5CPP_GET_THIS() / zval* object getThis(); // Register resources. If were using an object, put it into the object store. #define PHP5CPP_REGISTER_RESOURCE(obj_type, return_value, res, le) / { / PHP5CPP_GET_THIS(); / int rsrc_id ZEND_REGISTER_RESOURCE(object ? NULL : return_value, res, le); / if (object) { / php5cpp_obj *obj (php5cpp_obj *)zend_object_store_get_object(object TSRMLS_CC); / obj-u.obj_type res; / obj-rsrc_id rsrc_id; / obj-type is_ ## obj_type; / } / } // These are for parsing parameters and getting the actual object from the store. #define PHP5CPP_SET_OBJ(type) / { / php5cpp_obj *obj (php5cpp_obj *)zend_object_store_get_object( object TSRMLS_CC ); / type ## _instance obj-u.type; / } // Deprecated #define PHP5CPP_OBJ_PARAMS(type, params) / { / PHP5CPP_GET_THIS(); / if (object) { / if (params FAILURE) { / RETURN_FALSE; / } / PHP5CPP_SET_OBJ(type) / } / } // Deprecated #define PHP5CPP_OBJ_NO_PARAMS(type) / { / PHP5CPP_GET_THIS(); / if (object) { / if (ZEND_NUM_ARGS() ! 0) { / php_error(E_WARNING, didnt expect any arguments in %s(), get_active_function_name(TSRMLS_C)); / } / PHP5CPP_SET_OBJ(type) / } / } #define PHP5CPP_GET_OBJ(type) / { / PHP5CPP_GET_THIS(); / if (object) { / PHP5CPP_SET_OBJ(type) / } / if (type ## _instance NULL) { / php_error(E_WARNING, Get object fall in %s(), get_active_function_name(TSRMLS_C)); / } / } #define PHP5CPP_GET_OBJ_ZVAL(type, obj) / { / zval* object obj; / if (object) { / PHP5CPP_SET_OBJ(type) / } / if (type ## _instance NULL) { / php_error(E_WARNING, Get object fall in %s(), get_active_function_name(TSRMLS_C)); / } / } //static void php5cpp_object_free_storage_ ## type(zend_object *object TSRMLS_DC) #define PHP5CPP_OBJ_FREE_FUNCTION(type) / static void php5cpp_object_free_storage_ ## type(void *object TSRMLS_DC) / { / php5cpp_obj *obj (php5cpp_obj *) object; / zend_hash_destroy(obj-std.properties); / FREE_HASHTABLE(obj-std.properties); / if ( obj-u.type ) { / zend_list_delete(obj-rsrc_id); / } / efree(obj); / } #define PHP5CPP_OBJ_NEW_FUNCTION(type) / static zend_object_value php5cpp_object_new_ ## type(zend_class_entry *class_type TSRMLS_DC) / { / zend_object_value retval; / zval *tmp; / php5cpp_obj *obj (php5cpp_obj *)emalloc( sizeof(php5cpp_obj) ); / memset( obj, 0, sizeof(php5cpp_obj) ); / obj-std.ce class_type; / ALLOC_HASHTABLE( obj-std.properties ); / zend_hash_init( obj-std.properties, 0, NULL, ZVAL_PTR_DTOR, 0 ); / zend_hash_copy( obj-std.properties, / class_type-properties_info, / (copy_ctor_func_t) zval_add_ref, / (void *) tmp, / sizeof(zval *) ); / retval.handle zend_objects_store_put( obj, / NULL, / (zend_objects_free_object_storage_t)php5cpp_object_free_storage_ ## type, / NULL TSRMLS_CC ); / retval.handlers php5cpp_object_handlers_ ## type; / return retval; / } #endifphp7obj.h 新的#define SW_RETURN_STRINGL(s, l, dup) RETURN_STRINGL(s, l) #define SW_RETVAL_STRINGL(s, l, dup) do{RETVAL_STRINGL(s, l); if (dup 0) efree(s);}while(0) #define SW_RETVAL_STRING(s, dup) do{RETVAL_STRING(s); if (dup 0) efree(s);}while(0) #define SW_RETURN_STRING(val, duplicate) RETURN_STRING(val) #define SW_ZVAL_STRINGL(z, s, l, dup) ZVAL_STRINGL(z, s, l) #define SW_ZVAL_STRING(z,s,dup) ZVAL_STRING(z,s) #define SW_MAKE_STD_ZVAL(p) zval _stack_zval_##p; p (_stack_zval_##p) #define PZVAL_IS_REF(len) 0 static inline php5cpp_obj* php5obj_from_obj(zend_object *obj) { return (php5cpp_obj*)((char*)(obj) - XtOffsetOf(php5cpp_obj, std)); } #define Z_PHP5OBJ_P(zv) php5obj_from_obj(Z_OBJ_P((zv))) // Register the class entry.. #define PHP5CPP_REGISTER_CLASS(name, obj_name)/ {/ zend_class_entry ce;/ INIT_CLASS_ENTRY(ce, obj_name, php5cpp_##name##_methods);/ ce.create_object php5cpp_object_new_##name; / php5cpp_ce_##name zend_register_internal_class_ex(ce, NULL); / memcpy( php5cpp_object_handlers_##name, zend_get_std_object_handlers(),sizeof(zend_object_handlers) );/ php5cpp_object_handlers_##name.clone_obj NULL;/ } //#define ZEND_REGISTER_RESOURCE(return_value, result, le_result) ZVAL_RES(return_value,zend_register_resource(result, le_result)) #define PHP5CPP_GET_THIS() / zval* object getThis(); // Register resources. If were using an object, put it into the object store. #define PHP5CPP_REGISTER_RESOURCE(obj_type, return_value, res, le) / {/ PHP5CPP_GET_THIS();/ int rsrc_id 0;/ /*zend_register_resource(res,le);*// if (object) { / php5cpp_obj *obj Z_PHP5OBJ_P(object);/ obj-u.obj_type res;/ obj-rsrc_id rsrc_id;/ obj-type is_##obj_type;/ }/ } // These are for parsing parameters and getting the actual object from the store. #define PHP5CPP_SET_OBJ(type_name) / { / php5cpp_obj *obj Z_PHP5OBJ_P(object) ; / type_name ## _instance obj-u.type_name;/ } // Deprecated #define PHP5CPP_OBJ_PARAMS(type, params) / { / PHP5CPP_GET_THIS(); / if (object) { / if (params FAILURE) { / RETURN_FALSE; / } / PHP5CPP_SET_OBJ(type) / } / } // Deprecated #define PHP5CPP_OBJ_NO_PARAMS(type) / { / PHP5CPP_GET_THIS(); / if (object) { / if (ZEND_NUM_ARGS() ! 0) { / php_error(E_WARNING, didnt expect any arguments in %s(), get_active_function_name(TSRMLS_C)); / } / PHP5CPP_SET_OBJ(type) / } / } #define PHP5CPP_GET_OBJ(type) / {/ PHP5CPP_GET_THIS();/ PHP5CPP_SET_OBJ(type);/ } #define PHP5CPP_GET_OBJ_ZVAL(type, obj) / { / zval* object obj; / if (object) { / PHP5CPP_SET_OBJ(type) / } / if (type ## _instance NULL) { / php_error(E_WARNING, Get object_zal fall in %s(), get_active_function_name(TSRMLS_C)); / } / } #define PHP5CPP_OBJ_FREE_FUNCTION(type) / static void php5cpp_object_free_storage_ ## type(void *object TSRMLS_DC) / {/ php5cpp_obj *obj Z_PHP5OBJ_P((zval *)object);/ zend_object_std_dtor(obj-std);/ } #define PHP5CPP_OBJ_NEW_FUNCTION(type) / static zend_object* php5cpp_object_new_ ## type(zend_class_entry *class_type TSRMLS_DC) / {/ int objsize sizeof(php5cpp_obj);/ php5cpp_obj *obj(php5cpp_obj*)ecalloc(1,objsize);memset(obj,0,objsize);/ php_error(E_WARNING, create object %p in %s(),obj,get_active_function_name(TSRMLS_C));/ zend_object_std_init(obj-std, class_type TSRMLS_CC);object_properties_init(obj-std, class_type);/ obj-std.handlers php5cpp_object_handlers_##type;/ return obj-std;/ } #endif//_PHP7OBJ_H_《网络安全从零到精通全套学习大礼包》96节从入门到精通的全套视频教程免费领取如果你也想通过学网络安全技术去帮助就业和转行我可以把我自己亲自录制的96节 从零基础到精通的视频教程以及配套学习资料无偿分享给你。网络安全学习路线图想要学习 网络安全作为新手一定要先按照路线图学习方向不对努力白费。对于从来没有接触过网络安全的同学我帮大家准备了从零基础到精通学习成长路线图以及学习规划。可以说是最科学最系统的学习路线大家跟着这个路线图学习准没错。配套实战项目/源码所有视频教程所涉及的实战项目和项目源码学习电子书籍学习网络安全必看的书籍和文章的PDF市面上网络安全书籍确实太多了这些是我精选出来的面试真题/经验以上资料如何领取