Home >Backend Development >PHP Tutorial >Things to note when developing PHP extensions using VC++_PHP Tutorial
1. By default, C++ uses .cpp as the extension, and PHP is written in C. Therefore, the C connection provided by C++ must be used to exchange the specified symbol extern "C" to solve this problem. The following two parts of the statement must be Contains:
extern "C" {
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
... // Other C header files
}
and
extern "C" {
#ifdef COMPILE_DL_MYEXT
ZEND_GET_MODULE(myext)
#endif
}
2. STL Template definitions cannot be included in the C connection exchange specifier, and PHP needs to use the math.h header file, so math.h(514) error c2894: templates cannot be declared to have 'C' will be generated during compilation. linkage error message. To solve this problem, you need to add the following code to the header of your CPP file, which is before the extern "C" connector:
#ifdef WIN32
#include
#endif
3. Just like in C, all function prototypes must be declared in the header file (such as: php_myext.h) first. If the header file is not used, then it must be between the zend function structures of the CPP file (such as: ext.cpp) Declare all function prototypes, that is, before the following code:
function_entry myext_functions[] = {
PHP_FE(confirm_myext_compiled, NULL) /* For testing, remove later. */
{NULL, NULL, NULL}
};