PHP extension migration to PHP7 extension compatibility problem record _ php instance

Source: Internet
Author: User
Some kernel methods provided during PHP 7 extension compilation are not fully compatible with previous PHP versions. Many method parameters have been adjusted. The following are some problems encountered during the migration process. if you are interested, refer to PHP7 extension compiling. some kernel methods provided are not fully compatible with previous PHP versions. Many method parameters have been adjusted. The following are some problems encountered during the migration process. Record it to avoid further pitfalls.

Add_assoc_stringl

The method parameters are changed to four.

Add_assoc_stringl (parray, key, value, value_len );

During migration, you only need to delete the last parameter.

Add_assoc_string

The method parameters are changed from four to three.

Add_assoc_stringl (parray, key, value );

During migration, you only need to delete the last parameter.

Add_next_index_stringl

The method parameters are changed from four to three.

Add_next_index_stringl (parray, value, value_len );

During migration, you only need to delete the last parameter.

Add_next_index_string

The method parameters are changed from three to two.

Add_next_index_string (parray, value );

During migration, you only need to delete the last parameter.

RETURN_STRINGL

The method parameters are changed from three to two.

RETURN_STRINGL (value, length );

During migration, you only need to delete the last parameter.

Error: 'int64 _ MAX 'has not been declared in this scope

The reason is in-depth research. Add a line above # 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
 

Solution.

Create class

You can refer to mysqli extension mysqli_objects_new method in the mysqli. c file.

Variable Declaration is allocated from the stack, instead of stack allocation.

For example, the original code is

zval* sarray_l;ALLOC_INIT_ZVAL(sarray_l);array_init(sarray_l);

Change

zval sarray_l;array_init(&sarray_l);zend_hash_get_current_key_ex

The method parameters are 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);

During migration, you only need to delete the third and fifth parameters.

Error: 'Z _ TYPE_PP 'has not been declared in this scope

There is no Z_TYPE_PP macro. only Z_TYPE and Z_TYPE_P macro methods are defined.

H2 error: cannot be converted from 'zend _ string * 'to 'const char *'

In PHP 7, zend_string is used to store string processing. If you want to convert zend_string to const char. ZSTR_VAL () macro method is required. 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 is no IS_BOOL type. It is divided into IS_TRUE and IS_FALSE.

Error: 'Z _ BVAL 'has not been declared in this scope

No Z_BVAL macro exists. However, you can determine whether the type is IS_TRUE or IS_FALSE.

If the type is IS_TRUE, the value is true. If the type is IS_FALSE, the value 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) - XtOffsetOf(user_object, std));}/* }}} */#define Z_USEROBJ_P(zv) hsf_fetch_object(Z_OBJ_P((zv)))

Change zend_object_store_get_object to Z_USEROBJ_P.

Note that user_object is The struct you define.

The above is a description of the compatibility issue of PHP extension migration to PHP 7, and I hope to help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.