0

Trying to create simple Hello World PHP extension according manual.

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

hello.c

#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 errors:

/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
Cœur
  • 37,241
  • 25
  • 195
  • 267
vico
  • 17,051
  • 45
  • 159
  • 315

1 Answers1

0

I have tried the tutorial and get error when run make. Then, I found that function_entry is not used for PHP 5.4 or 5.5. I googled and found that: if I replace function_entry by zend_function_entry, it will solve the problem. It work fine for me.