PHP 扩展错误 :

标签 php c php-extension

我正在尝试创建 php 扩展。

这是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

这是 php_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

这是hello.c文件

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_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);
}

当我使用以下命令构建它时-

$ phpize
$ ./configure --enable-hello
$ make

得到这个错误-

/usr/include/php/ext/hello/hello.c:8:5: warning: braces around scalar initializer [enabled by default]
/usr/include/php/ext/hello/hello.c:8:5: warning: (near initialization for 'hello_functions[0]') [enabled by default]
/usr/include/php/ext/hello/hello.c:8:5: warning: initialization makes integer from pointer without a cast [enabled by default]
/usr/include/php/ext/hello/hello.c:8:5: warning: (near initialization for 'hello_functions[0]') [enabled by default]
/usr/include/php/ext/hello/hello.c:8:5: error: initializer element is not computable at load time
/usr/include/php/ext/hello/hello.c:8:5: error: (near initialization for 'hello_functions[0]')
/usr/include/php/ext/hello/hello.c:8:5: warning: excess elements in scalar initializer [enabled by default]
/usr/include/php/ext/hello/hello.c:8:5: warning: (near initialization for 'hello_functions[0]') [enabled by default]
/usr/include/php/ext/hello/hello.c:8:5: warning: excess elements in scalar initializer [enabled by default]
/usr/include/php/ext/hello/hello.c:8:5: warning: (near initialization for 'hello_functions[0]') [enabled by default]
/usr/include/php/ext/hello/hello.c:8:5: warning: excess elements in scalar initializer [enabled by default]
/usr/include/php/ext/hello/hello.c:8:5: warning: (near initialization for 'hello_functions[0]') [enabled by default]
/usr/include/php/ext/hello/hello.c:8:5: warning: excess elements in scalar initializer [enabled by default]
/usr/include/php/ext/hello/hello.c:8:5: warning: (near initialization for 'hello_functions[0]') [enabled by default]
/usr/include/php/ext/hello/hello.c:9:5: warning: braces around scalar initializer [enabled by default]
/usr/include/php/ext/hello/hello.c:9:5: warning: (near initialization for 'hello_functions[1]') [enabled by default]
/usr/include/php/ext/hello/hello.c:9:5: warning: initialization makes integer from pointer without a cast [enabled by default]
/usr/include/php/ext/hello/hello.c:9:5: warning: (near initialization for 'hello_functions[1]') [enabled by default]
/usr/include/php/ext/hello/hello.c:9:5: warning: excess elements in scalar initializer [enabled by default]
/usr/include/php/ext/hello/hello.c:9:5: warning: (near initialization for 'hello_functions[1]') [enabled by default]
/usr/include/php/ext/hello/hello.c:9:5: warning: excess elements in scalar initializer [enabled by default]
/usr/include/php/ext/hello/hello.c:9:5: warning: (near initialization for 'hello_functions[1]') [enabled by default]
/usr/include/php/ext/hello/hello.c:17:5: warning: initialization from incompatible pointer type [enabled by default]
/usr/include/php/ext/hello/hello.c:17:5: warning: (near initialization for 'hello_module_entry.functions') [enabled by default]

我是新手,我该如何解决这个问题?

最佳答案

我得到了解决方案。在 hello.c 文件中,我使用的 function_entry 不适用于 php 5.4 或更高版本。 使用 zend_function_entry 代替 function_entry。

关于PHP 扩展错误 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16956068/

相关文章:

php - curl 问题 : same request, 不同的响应

php - 为什么即使数据库为空,图像也会显示损坏?

c - 编译C程序后Eclipse CDT意外输出

c - 函数指针和函数地址

PHP 扩展检查 key 是否存在

phpize 和 php api 版本不匹配

php - 从 PHP 扩展中获取运行脚本的名称

php - 单击图像时如何制作图像以在 codeigniter View 中放大 Bootstrap ?

Apache 2.4.3 和 PHP 5.4.7 上的 PHP 语法错误(foreach 模板语法)

C - 在多个函数中使用结构