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?
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!
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.