php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39522 PHP's header files are unusable for C++ extensions
Submitted: 2006-11-15 07:35 UTC Modified: 2006-11-15 10:19 UTC
From: phoemix at harmless dot hu Assigned:
Status: Not a bug Package: Compile Failure
PHP Version: 5.2.0 OS: freebsd6, linux (but irrelevant)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phoemix at harmless dot hu
New email:
PHP Version: OS:

 

 [2006-11-15 07:35 UTC] phoemix at harmless dot hu
Description:
------------
(the php version is irrelevant, i just couldn't pick that for the "compile failure" type. i had it on 4.x and on 5.x both"

create a new extensions, have a C++ source file, and include some php headers. it will fail on two points.

1) C++ doesn't support "long long". lot's of architectures has stdint.h (i think it's C99). that should be used instead of "long long"-ing manually.

2) C++ prohobits havint a trailing coma at the end of an enum's last member.

i have created a patch for the FreeBSD ports system. the errors are in snprintf.h and in php_stream_filter_api.h/.

--- patch follows ---
diff -ur php-5.2.0-orig/main/snprintf.h php-5.2.0/main/snprintf.h
--- php-5.2.0-orig/main/snprintf.h      Sun Jan  1 13:50:17 2006
+++ php-5.2.0/main/snprintf.h   Tue Nov 14 14:23:31 2006
@@ -120,8 +120,14 @@
 #else
 # define WIDE_INT              long
 #endif
+#ifdef __FreeBSD__
+#include <stdint.h>
+typedef int64_t wide_int;
+typedef uint64_t u_wide_int;
+#else
 typedef WIDE_INT wide_int;
 typedef unsigned WIDE_INT u_wide_int;
+#endif

 typedef int bool_int;

diff -ur php-5.2.0-orig/main/streams/php_stream_filter_api.h php-5.2.0/main/streams/php_stream_filter_api.h
--- php-5.2.0-orig/main/streams/php_stream_filter_api.h Sun Jan  1 13:50:18 2006
+++ php-5.2.0/main/streams/php_stream_filter_api.h      Tue Nov 14 14:24:33 2006
@@ -62,7 +62,7 @@
 typedef enum {
        PSFS_ERR_FATAL, /* error in data stream */
        PSFS_FEED_ME,   /* filter needs more data; stop processing chain until more is available */
-       PSFS_PASS_ON,   /* filter generated output buckets; pass them on to next in chain */
+       PSFS_PASS_ON    /* filter generated output buckets; pass them on to next in chain */
 } php_stream_filter_status_t;

 /* Buckets API. */


Reproduce code:
---------------
create a new extensions, have a C++ source file, and include some php headers. it will fail on two points.

Expected result:
----------------
a clean compilation.

Actual result:
--------------
i don't have the error output yet, since my local version is fixed manually.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-15 09:46 UTC] tony2001@php.net
We have several C++ extensions in PECL and I'm happen to be the author of one. And I didn't/don't see any problems with C++ and PHP headers, even on FreeBSD.
Please elaborate and show what exactly is wrong before posting a patch for a bug which is not reproducible.
 [2006-11-15 09:53 UTC] phoemix at harmless dot hu
i have this in my header file:
extern "C" {
#include "php.h"
#include "php_ini.h"
#include "SAPI.h"
#include "ext/standard/info.h"
#include "ext/standard/head.h"
}

and when i compile it i have these errors:
g++ -c -O2 -march=pentium4 -ggdb -W -Wall -pedantic -pipe -I/usr/local/include -fpic -DCOMPILE_DL_POLYLOOK=1 -Idbapi/ -Iinclude/ `/var/jails/httpdtest/usr/local/bin/php-config --includes` -o phpext/obj/phpfuncs.o phpext/phpfuncs.cc
In file included from /usr/local/include/php/main/php.h:242,
                 from phpext/phpfuncs.cc:7:
/usr/local/include/php/main/snprintf.h:138: error: expected `,' or `...' before "num"
/usr/local/include/php/main/snprintf.h:139: error: ISO C++ forbids declaration of `wide_int' with no type
/usr/local/include/php/main/snprintf.h:144: error: expected `,' or `...' before "num"
/usr/local/include/php/main/snprintf.h:145: error: ISO C++ forbids declaration of `u_wide_int' with no type
gmake: *** [phpext/obj/phpfuncs.o] Error 1


and:
g++ -c -O2 -march=pentium4 -ggdb -W -Wall -pedantic -pipe -I/usr/local/include -fpic -DCOMPILE_DL_POLYLOOK=1 -Idbapi/ -Iinclude/ `/var/jails/httpdtest/usr/local/bin/php-config --includes` -o phpext/obj/phpfuncs.o phpext/phpfuncs.cc
In file included from /usr/local/include/php/main/php_streams.h:104,
                 from /usr/local/include/php/main/php.h:408,
                 from phpext/phpfuncs.cc:7:
/usr/local/include/php/main/streams/php_stream_filter_api.h:66: error: comma at end of enumerator list
gmake: *** [phpext/obj/phpfuncs.o] Error 1
 [2006-11-15 09:57 UTC] tony2001@php.net
>i have this in my header file

>In file included from /usr/local/include/php/main/php.h:242,
is this the header file? ----->   from phpext/phpfuncs.cc
 [2006-11-15 09:59 UTC] phoemix at harmless dot hu
no, sorry, that's a source file.
it includes that headers from php
 [2006-11-15 10:01 UTC] tony2001@php.net
.. and it's apparently missing extern "C" { } block.
No bug -> bogus.
 [2006-11-15 10:03 UTC] phoemix at harmless dot hu
it _do_ has the extern "C". read my previous post please. i have pasted the way i include it, it's in an extern "C" block.

let me quote my previous post:
[2006-11-15 09:53:25] phoemix at harmless dot hu
--- chop with axe here ---
i have this in my header file:
extern "C" {
#include "php.h"
#include "php_ini.h"
#include "SAPI.h"
#include "ext/standard/info.h"
#include "ext/standard/head.h"
}
--- chop with axe here ---
now, where is the extern "C" missing? i see it there.
please double-check my previous post
 [2006-11-15 10:10 UTC] tony2001@php.net
I your previous post you were talking about *header*, while this is not what GCC says. I don't know what is in your .cc file and what is in your header, as you didn't show me anything except for a few lines.
Please ask any questions related to custom module development in pecl-dev@lists.php.net, this is not a support forum, but a bug tracking system.
 [2006-11-15 10:15 UTC] phoemix at harmless dot hu
yes, it was a typo. it's a source file. as i have corrected myself, and as it seems from the g++ command line, the way it is being ran.

yes, you do know what is in my .cc file, as i had posted it. for your sake it is here again:

<beginning of _SOURCE_ file>
extern "C" {
#include "php.h"
#include "php_ini.h"
#include "SAPI.h"
#include "ext/standard/info.h"
#include "ext/standard/head.h"
}

#include <stdio.h>
#include <stdarg.h>
#include <time.h>

#include "debug.hh"
#include "logger.hh"
#include "phpfuncs.hh"
#include "skin.hh"
#include "phpdb.hh"

#include <string>
#include <set>

<end of header includes>
namespace phpfuncs {


this much shoud be enough.
i only show the relevant lines.

i'm here to report a bug, and not to ask questions. so, please don't make this bug reporting place a support center, because it's simply not that. thanks.
 [2006-11-15 10:19 UTC] tony2001@php.net
Use PECL/rar as an example.
It uses the same C headers in C++ code without any problems.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Dec 22 21:00:01 2025 UTC