0

I have a question about PHP. I use Ubuntu but I have different PHP builds that I built myself in /opt/php. I have a problem (using PHP 5.3.8) when enabling an extension doing the following synopsis

cd my-ext
/opt/php/5.3.8/bin/phpize
./configure --args...
make
make install

And I get the following error:

PHP_FE_END (undefined function)

From a Japanese blog and PHP SVN source (see links below)

http://d.hatena.ne.jp/SeaHacker/20110825

http://marc.info/?l=php-cvs&m=131161504128077

Apparently, the hack is to replace PHP_FE_FUNCTION by {NULL,NULL,NULL} so I added this in my code:

sed -i 's|PHP_FE_END|{NULL,NULL,NULL}|' /opt/php/5.3.8/ext/**/*.c
sed -i 's|ZEND_MOD_END|{NULL,NULL,NULL}|' /opt/php/5.3.8/ext/**/*.c

And this fixes the bug. But I am not a C expert so I know it works but I don't know why so it's kind of frustrating. Anybody could shred some light on that matter?

2 Answers 2

3

The PHP_FE_FUNCTION macro is supposed to be defined with the value {NULL,NULL,NULL} in "$PREFIX/include/php/main/php.h" (for you, $PREFIX may be /opt). ZEND_MOD_END is supposed to be defined as { NULL, NULL, NULL, 0 } in "Zend/zend_modules.h". Both are initializers used to initialize a variable's value when declaring it.

For some reason, the copy of these headers installed for PHP 5.3.8 (and perhaps other versions) are sometimes missing these macros, though it exists in the headers in the source distribution. Replacing the macros with {NULL,NULL,NULL} works because, well, that's what the value is supposed to be for PHP_FE_FUNCTION. For ZEND_MOD_END it works because if there are fewer values in the initializer than array elements/struct members, any remaining elements/members are zero initialized (see C99, § 6.7.8-21 for the full story). For example:

int ii[10] = {NULL,NULL,NULL}; // ii[3] through ii[9] are 0
struct {
    int *pa, *pb, *pc,
        d,e,f;
} s = {NULL, NULL, NULL}; // s.d, .e, .f are 0

Another fix for the error is to replace the installed file, which will also fix building other extensions:

  1. diff the installed main/php.h with the copy in the source and look for incompatible changes. As long as the source and installed versions are the same, there shouldn't be too many changes (I observed a declaration for php_win32_docref2_from_error on MS Windows systems).
  2. If there don't appear to be any problems, copy the source main/php.h over the installed php.h.

The second replacement (of the macro ZEND_MOD_END) only applies to some extensions, such as imap. For these, you could also repeat the alternate fix for Zend/zend_API.h (for ZEND_FE_END) and Zend/zend_modules.h (for ZEND_MOD_END).

1

Perhaps "make script" does`t find main/php.h of your php version in include path. (you may have includes in /opt/php/5.3.8/includes or whatever).

In most case the best way is to use php-config of your php installation, try this:

./configure --with-php-config=/opt/php/5.3.8/bin/php-config

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .