Home >Backend Development >PHP Tutorial >Due to the php7 kernel upgrade, when developing php extensions, do we need to develop two versions: php5 and php7?

Due to the php7 kernel upgrade, when developing php extensions, do we need to develop two versions: php5 and php7?

WBOY
WBOYOriginal
2016-07-06 13:53:24966browse

I have checked several extensions of Brother Niao, and they are all new branches to write php7 version of the extension;
As for the swoole extension, it uses a php7-swapper.h to package it, but it uses PHP kernel stuff is relatively easy to operate with macros.

For example, under the php5 version extension there is the following definition:

<code>typedef struct _test_obj {
    zend_object std; // 放到头部
    my_test_struct *my;
    int count;
} test_obj;
</code>

According to the php7 extension improvement suggestions, this structure needs to be modified to:

<code>typedef struct _test_obj {
    my_test_struct *my;
    int count;
    zend_object std; // 放到尾部
} test_obj;
</code>

Wait a minute, if you use to wrap it, the code will look uglier. But if you don’t do this and develop it in two branches, you will have to modify two copies of the code every time, which is more troublesome.

I don’t know if you guys have any good ideas, please give me some advice, thank you!

Reply content:

I have checked several extensions of Brother Niao, and they are all new branches to write php7 version of the extension;
As for the swoole extension, it uses a php7-swapper.h to package it, but it uses PHP kernel stuff is relatively easy to operate with macros.

For example, under the php5 version extension there is the following definition:

<code>typedef struct _test_obj {
    zend_object std; // 放到头部
    my_test_struct *my;
    int count;
} test_obj;
</code>

According to the php7 extension improvement suggestions, this structure needs to be modified to:

<code>typedef struct _test_obj {
    my_test_struct *my;
    int count;
    zend_object std; // 放到尾部
} test_obj;
</code>

Wait a minute, if you use to wrap it, the code will look uglier. But if you don’t do this and develop it in two branches, you will have to modify two copies of the code every time, which is more troublesome.

I don’t know if you guys have any good ideas, please give me some advice, thank you!

The best way for user experience is to write through macros, so users don’t have to choose a version. Of course, the disadvantage of writing this way is that the two pieces of code will be mixed when they overlap. After all, PHP7 has made significant changes to the infrastructure. Although most of the macros that come with PHP7 still follow the writing method of the old version, the application variables on the heap, and some related to the reference mechanism , and other commonly used macros have changed, so it is quite a challenge to merge and write them together. If you find it troublesome, just write them separately like Brother Bird. At present, most extensions are written in separate modes first, and then merged together when they are more mature.

@有明 Thank you, I am sure to write them separately now, and then take a look after php7 is completely stable.

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