C ++ — Создать расширение PHP

Попытка создать простое PHP-расширение Hello World в соответствии с руководство.

config.m4

PHP_ARG_ENABLE(hello, whether to enable Hello
World support,
[ --enable-hello   Enable Hello World support])
if test "$PHP_HELLO" = "yes"; then
AC_DEFINE(HAVE_HELLO, 1, [Whether you have Hello World])
PHP_NEW_EXTENSION(hello, hello.c, $ext_shared)
fi

hello.h

#ifndef PHP_HELLO_H
#define PHP_HELLO_H 1
#define PHP_HELLO_WORLD_VERSION "1.0"#define PHP_HELLO_WORLD_EXTNAME "hello"
PHP_FUNCTION(hello_world);

extern zend_module_entry hello_module_entry;
#define phpext_hello_ptr &hello_module_entry

#endif

Привет

#ifdef HAVE_CONFIG_H
#include "config.h"#endif
#include "php.h"#include "hello.h"
static function_entry hello_functions[] = {
PHP_FE(hello_world, NULL)
{NULL, NULL, NULL}
};

zend_module_entry hello_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
PHP_HELLO_WORLD_EXTNAME,
hello_functions,
NULL,
NULL,
NULL,
NULL,
NULL,
#if ZEND_MODULE_API_NO >= 20010901
PHP_HELLO_WORLD_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_HELLO
ZEND_GET_MODULE(hello)
#endif

PHP_FUNCTION(hello_world)
{
RETURN_STRING("Hello World", 1);
}

ошибки make throws:

/bin/bash /home/ggg/cpp/php/libtool --mode=compile cc  -I. -I/home/ggg/cpp/php -DPHP_ATOM_INC -I/home/ggg/cpp/php/include -I/home/ggg/cpp/php/main -I/home/ggg/cpp/php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /home/ggg/cpp/php/hello.c -o hello.lo
libtool: compile:  cc -I. -I/home/ggg/cpp/php -DPHP_ATOM_INC -I/home/ggg/cpp/php/include -I/home/ggg/cpp/php/main -I/home/ggg/cpp/php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/ggg/cpp/php/hello.c  -fPIC -DPIC -o .libs/hello.o
/home/ggg/cpp/php/hello.c:8:8: error: unknown type name 'function_entry'
static function_entry hello_functions[] = {
^
/home/ggg/cpp/php/hello.c:9:5: warning: braces around scalar initializer
PHP_FE(hello_world, NULL)
^
/home/ggg/cpp/php/hello.c:9:5: warning: (near initialization for 'hello_functions[0]')
/home/ggg/cpp/php/hello.c:9:5: warning: initialization makes integer from pointer without a cast
/home/ggg/cpp/php/hello.c:9:5: warning: (near initialization for 'hello_functions[0]')
/home/ggg/cpp/php/hello.c:9:5: error: initializer element is not computable at load time
/home/ggg/cpp/php/hello.c:9:5: error: (near initialization for 'hello_functions[0]')
/home/ggg/cpp/php/hello.c:9:5: warning: excess elements in scalar initializer
/home/ggg/cpp/php/hello.c:9:5: warning: (near initialization for 'hello_functions[0]')
/home/ggg/cpp/php/hello.c:9:5: warning: excess elements in scalar initializer
/home/ggg/cpp/php/hello.c:9:5: warning: (near initialization for 'hello_functions[0]')
In file included from /usr/include/php5/main/php.h:40:0,
from /home/ggg/cpp/php/hello.c:5:
/usr/include/php5/Zend/zend_API.h:71:129: warning: excess elements in scalar initializer
#define ZEND_FENTRY(zend_name, name, arg_info, flags) { #zend_name, name, arg_info, (zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
^
/usr/include/php5/Zend/zend_API.h:77:38: note: in expansion of macro 'ZEND_FENTRY'
#define ZEND_FE(name, arg_info)      ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
^
/usr/include/php5/main/php.h:353:18: note: in expansion of macro 'ZEND_FE'
#define PHP_FE   ZEND_FE
^
/home/ggg/cpp/php/hello.c:9:5: note: in expansion of macro 'PHP_FE'
PHP_FE(hello_world, NULL)
^
/usr/include/php5/Zend/zend_API.h:71:129: warning: (near initialization for 'hello_functions[0]')
#define ZEND_FENTRY(zend_name, name, arg_info, flags) { #zend_name, name, arg_info, (zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
^
/usr/include/php5/Zend/zend_API.h:77:38: note: in expansion of macro 'ZEND_FENTRY'
#define ZEND_FE(name, arg_info)      ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
^
/usr/include/php5/main/php.h:353:18: note: in expansion of macro 'ZEND_FE'
#define PHP_FE   ZEND_FE
^
/home/ggg/cpp/php/hello.c:9:5: note: in expansion of macro 'PHP_FE'
PHP_FE(hello_world, NULL)
^
/usr/include/php5/Zend/zend_API.h:71:129: warning: excess elements in scalar initializer
#define ZEND_FENTRY(zend_name, name, arg_info, flags) { #zend_name, name, arg_info, (zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
^
/usr/include/php5/Zend/zend_API.h:77:38: note: in expansion of macro 'ZEND_FENTRY'
#define ZEND_FE(name, arg_info)      ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
^
/usr/include/php5/main/php.h:353:18: note: in expansion of macro 'ZEND_FE'
#define PHP_FE   ZEND_FE
^
/home/ggg/cpp/php/hello.c:9:5: note: in expansion of macro 'PHP_FE'
PHP_FE(hello_world, NULL)
^
/usr/include/php5/Zend/zend_API.h:71:129: warning: (near initialization for 'hello_functions[0]')
#define ZEND_FENTRY(zend_name, name, arg_info, flags) { #zend_name, name, arg_info, (zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
^
/usr/include/php5/Zend/zend_API.h:77:38: note: in expansion of macro 'ZEND_FENTRY'
#define ZEND_FE(name, arg_info)      ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
^
/usr/include/php5/main/php.h:353:18: note: in expansion of macro 'ZEND_FE'
#define PHP_FE   ZEND_FE
^
/home/ggg/cpp/php/hello.c:9:5: note: in expansion of macro 'PHP_FE'
PHP_FE(hello_world, NULL)
^
/home/ggg/cpp/php/hello.c:10:5: warning: braces around scalar initializer
{NULL, NULL, NULL}
^
/home/ggg/cpp/php/hello.c:10:5: warning: (near initialization for 'hello_functions[1]')
/home/ggg/cpp/php/hello.c:10:5: warning: initialization makes integer from pointer without a cast
/home/ggg/cpp/php/hello.c:10:5: warning: (near initialization for 'hello_functions[1]')
/home/ggg/cpp/php/hello.c:10:5: warning: excess elements in scalar initializer
/home/ggg/cpp/php/hello.c:10:5: warning: (near initialization for 'hello_functions[1]')
/home/ggg/cpp/php/hello.c:10:5: warning: excess elements in scalar initializer
/home/ggg/cpp/php/hello.c:10:5: warning: (near initialization for 'hello_functions[1]')
/home/ggg/cpp/php/hello.c:18:5: warning: initialization from incompatible pointer type
hello_functions,
^
/home/ggg/cpp/php/hello.c:18:5: warning: (near initialization for 'hello_module_entry.functions')
Makefile:180: recipe for target 'hello.lo' failed
make: *** [hello.lo] Error 1

0

Решение

Я пробовал учебник и получаю ошибку при запуске make.
Затем я обнаружил, что function_entry не используется для PHP 5.4 или 5.5. Я гуглил и обнаружил, что: если я заменю function_entry на zend_function_entry, это решит проблему.
Это прекрасно работает для меня.

0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]