PHP extension migration to PHP7 extended compatibility issue record, PHP7 compatibility _php tutorial

Source: Internet
Author: User

PHP extension migrated to PHP7 extended compatibility issue record, PHP7 compatibility


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.

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)-Xtoffsetof (U Ser_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.

The above is a description of the PHP extension migration to the PHP7 extension compatibility issue record, we hope to help.

Articles you may be interested in:

    • ECshop compatibility issues when migrating to the PHP7 version

http://www.bkjia.com/PHPjc/1100318.html www.bkjia.com true http://www.bkjia.com/PHPjc/1100318.html techarticle PHP Extension Migration for PHP7 extended compatibility issue records, PHP7 compatibility PHP7 extension when written, some of the kernel methods provided are not fully compatible with previous versions of PHP. There are many ...

  • 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.