Home  >  Article  >  Backend Development  >  PHP extension migration to PHP7 extension compatibility issue record, php7 compatibility_PHP tutorial

PHP extension migration to PHP7 extension compatibility issue record, php7 compatibility_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:59:001026browse

PHP extension migration is a record of PHP7 extension compatibility issues, php7 compatibility

When the PHP7 extension was written, some of the kernel methods provided were not completely compatible with previous PHP versions. compatible. Many method parameters have been adjusted. Below are some issues encountered during the migration process. Record it to prevent others from stepping into the trap again.

add_assoc_stringl

The method parameters are changed to four.

add_assoc_stringl(parray, key, value, value_len);

When migrating, just delete the last parameter.

add_assoc_string

The method parameters have been changed from four to three.

add_assoc_stringl(parray, key, value);

When migrating, just delete the last parameter.

add_next_index_stringl

The method parameters have been changed from four to three.

add_next_index_stringl(parray, value, value_len);

When migrating, just delete the last parameter.

add_next_index_string

The method parameters have been changed from three to two.

add_next_index_string(parray, value);

When migrating, just delete the last parameter.

RETURN_STRINGL

The method parameters have been changed from three to two.

RETURN_STRINGL(value, length);

When migrating, just 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 <stdint.h> 
#ifndef INT64_MAX
# define INT64_MAX INT64_C( 9223372036854775807)
#endif
#ifndef INT64_MIN
# define INT64_MIN (-INT64_C( 9223372036854775807)-1)
#endif

Solved.

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 to the stack.

For example, the original code is

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

changed to

zval sarray_l;
array_init(&sarray_l);
zend_hash_get_current_key_ex

Method parameters 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, just 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 the definition 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 uses zend_string for storage. If you want to convert zend_string to const char. Need to use 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 is no IS_BOOL type. Instead, it is divided into IS_TRUE and IS_FALSE.

Error: 'Z_BVAL' has not been declared in this scope

There is no Z_BVAL macro anymore. But it can be determined by whether the type is IS_TRUE and 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)))

Then change zend_object_store_get_object to Z_USEROBJ_P.

Note that user_object is the structure you defined.

The above is a description of the compatibility issues recorded for PHP extension migration to PHP7 extension. I hope it will be helpful to everyone.

Articles you may be interested in:

  • Compatibility issues encountered when ECshop migrates to PHP7 version

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1100318.htmlTechArticlePHP extension migration is recorded as PHP7 extension compatibility issue, php7 compatibility When writing PHP7 extension, some cores are provided The method is not fully compatible with previous versions of PHP. There are quite a few...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn