New: Create and edit Word documents with DOCX Editor in WebViewer
By Minh Nguyen (Mitch) | 2018 Nov 16
We are happy to announce that we have added PHP 7 bindings to our PDF SDK through SWIG 3. This blog will outline some of the changes we made to our PHP PDF library so that it would support both PHP5/SWIG2 and PHP7/SWIG3.
There are some major changes in APIs and data structures between PHP 5 and PHP 7. In order to support PHP 7, we have made some changes to PDFNetPHP.i
and PDFNetUStringPHP.i
in PDFNetPHP:
//@data {"displayAs": ""}//
zval **data
Z_ARRVAL_PP, Z_TYPE_PP
zend_hash_get_current_data_ex(_,_,_)
ZVAL_STRINGL(_,_,_,_)
//@data {"displayAs": ""}//
zval *data
Z_ARRVAL_P, Z_TYPE_P
zend_hash_get_current_data_ex(_,_)
ZVAL_STRINGL(_,_,_)
We also made the following changes to CMakeLists.txt:
//@data {"displayAs": ""}//
execute_process(
COMMAND ${SWIG_EXECUTABLE} -c++ -php -DNTS -DSWIGHIDDEN_SIG -I${PDFNetC_Include_Dir} -outdir ${PDFNetPHP_SourcesDir} -o ${PDFNetPHP_SourcesDir}/PDFNetPHP.cpp -oh ${PDFNetPHP_SourcesDir}/PDFNetPHP.hpp PDFNetPHP.i
)
//@data {"displayAs": ""}//
execute_process(
COMMAND ${SWIG_EXECUTABLE} -c++ -php7 -DNTS -DSWIGHIDDEN_SIG -I${PDFNetC_Include_Dir} -outdir ${PDFNetPHP_SourcesDir} -o ${PDFNetPHP_SourcesDir}/PDFNetPHP.cpp -oh ${PDFNetPHP_SourcesDir}/PDFNetPHP.hpp PDFNetPHP.i
)
Instead of having separate solutions for PHP 5 and PHP 7, we were able to combine them into a single build by using a php-config
executable in CMake to obtain PHP package information:
//@data {"displayAs": ""}//
find_program(PHP_CONFIG_EXECUTABLE NAMES php-config7 php-config5 php-config4 php-config)
execute_process(
COMMAND
${PHP_CONFIG_EXECUTABLE} --vernum
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND sed -ne "s/....$//p"
OUTPUT_VARIABLE PHP_MAJOR_VERSION
)
Once PHP_MAJOR_VERSION
is obtained, we can set the appropriate arguments on SWIG:
//@data {"displayAs": ""}//
if (PHP_MAJOR_VERSION LESS 7)
set(php_version "php")
else()
set(php_version "php7")
endif()
execute_process(
COMMAND ${SWIG_EXECUTABLE} -c++ -${php_version} …
)
The next changes are using preprocessor directives in the interface files:
#if PHP_MAJOR_VERSION >= 7
...
#else
...
#endif
For more information about setup instructions, please click here.
In this blog, we outlined how we added support for PHP 7 without the need for a separate configuration, while also ensuring seamless support for any newer PHP/SWIG versions. If you have any questions, please feel free to contact us and we will be happy to help.
Minh Nguyen (Mitch)
Share this post
PRODUCTS
Popular Content