When the PHP7 extension is written, some of the kernel methods provided are not fully compatible with previous versions of PHP. There are many ways to adjust the parameters. The following are some of the issues encountered during the migration process. Record it and avoid the pit.
PHP7 extended development of Hello Word
The creation object of the vernacular PHP7 expansion development
Add_assoc_stringl
Change the method parameter to four.
Add_assoc_stringl (Parray, key, value, Value_len);
When migrating, simply delete the last parameter.
Add_assoc_string
The method parameters were changed from four to three.
Add_assoc_stringl (Parray, key, value);
When migrating, simply delete the last parameter.
Add_next_index_stringl
The method parameters were changed from four to three.
Add_next_index_stringl (Parray, value, Value_len);
When migrating, simply delete the last parameter.
Add_next_index_string
The method parameters were changed from three to two.
Add_next_index_string (Parray, value);
When migrating, simply delete the last parameter.
Return_stringl
The method parameters were changed from three to two.
Return_stringl (value, length);
When migrating, simply delete the last parameter.
Error: ' Int64_max ' has not been declared in this scope
The reason for this is in-depth study. Add a line to the #include "php.h"
#include
#ifndef int64_max# define Int64_max int64_c (9223372036854775807) #endif #ifndef int64_min# Define Int64_min (-int64_c (9223372036854775807)-1) #endif
Solve.
Create Class
You can refer to the Mysqli_objects_new method in the mysqli extension mysqli.c file.
Variable declarations are allocated from the heap and are allocated on the stack instead.
For example, the original code is
zval* sarray_l; Alloc_init_zval (sarray_l); Array_init (sarray_l);
Switch
Zval Sarray_l;array_init (&sarray_l);
Zend_hash_get_current_key_ex
The method parameters were changed from six to four.
Zend_api int Zend_fastcall zend_hash_get_current_key_ex (const HashTable *HT, zend_string **str_index, Zend_ulong *num_ Index, hashposition *pos);
When migrating, simply delete the third and fifth parameters.
Error: ' Z_TYPE_PP ' has not been declared in this scope
There are no Z_TYPE_PP macros, only definitions of Z_type and z_type_p macro methods.
<>H2 error: Cannot convert from ' zend_string* ' to ' const char* '
The processing of strings in PHP7 is stored using zend_string. If you want to convert zend_string to const char. You need to use the Zstr_val () macro method. The code is as follows:
zend_string *str;char *sptr;.....sptr = zstr_val (str);
Error: ' Is_bool ' has not been declared in this scope
There are no is_bool types. They are divided into is_true and Is_false.
Error: ' Z_bval ' has not been declared in this scope
There are no Z_bval macros. However, it can be judged by whether the type is is_true and Is_false. If the type is Is_true, the value is TRUE. The value is False if the type is is_false.
Error: ' Zend_object_store_get_object ' has not been declared in this scope
Add the following code:
Static inline Hsf_object *hsf_fetch_object (zend_object *obj)/* {{{* * * * return (User_object *) ((char*) (obj)-XTOFFSE TOf (User_object, STD)); }/*}}} */#define Z_USEROBJ_P (ZV) Hsf_fetch_object (Z_obj_p ((ZV)))
Then change the zend_object_store_get_object to z_userobj_p. Note that User_object is the structure you define.
Original link: PHP extension migration to compatible PHP7 records, reproduced please indicate the source!