Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP8 extension support? #1161

Closed
rieschl opened this issue Sep 2, 2020 · 12 comments
Closed

PHP8 extension support? #1161

rieschl opened this issue Sep 2, 2020 · 12 comments

Comments

@rieschl
Copy link

rieschl commented Sep 2, 2020

Bug Report

Out of curiosity I wanted to try running the test pipeline (Docker), mainly phpunit tests of one of our projects on PHP8 beta2 to see if there are any code errors, when I discovered that the MongoDB extension cannot be built in php8 because of some C errors (apparently... I don't really understand those C exceptions).

Environment

I used the Docker image php:8.0.0beta2 with pickle as replacement for pecl (pecl isn't available anymore in php8).
That's the Dockerfile

FROM php:8.0.0beta2

RUN \
    apt-get update -yqq \
    && apt-get install -y gnupg git wget zlib1g-dev zlibc zlib1g zlib1g-dev libicu-dev g++ libzip4 libzip-dev \
        unzip openssh-client libc6 libgcc1 ca-certificates lsb-release xdg-utils wget openssl \
    \
    && docker-php-ext-install zip \
    \
    && wget https://github.com/FriendsOfPHP/pickle/releases/download/v0.6.0/pickle.phar -O /usr/local/bin/pickle \
    && chmod +x /usr/local/bin/pickle \
    \
    && pickle install --defaults --no-interaction mongodb \
    && docker-php-ext-enable mongodb

Expected and Actual Behavior

Well, the expected behavior is the extension being built successfully. Instead some exceptions are thrown.
To rule out pickle as source of error I tried the same Dockerfile with php:7.4-cli without error.

Debug Log

The Docker image build process errors on pickle install --defaults --no-interaction mongodb with the following error:

2: mkdir .libs
2:  cc -I. -I/tmp/mongodb/mongodb-1.8.0 -I/tmp/pickle-df53dcc69def9406150485674c8742825c40ef02/include -I/tmp/pickle-df53dcc69def9406150485674c8742825c40ef02/main -I/tmp/mongodb/mongodb-1.8.0 -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/tmp/mongodb/mongodb-1.8.0/src/libmongoc/src/common/ -I/tmp/mongodb/mongodb-1.8.0/src/libmongoc/src/libbson/src/ -I/tmp/mongodb/mongodb-1.8.0/src/libmongoc/src/libbson/src/jsonsl/ -I/tmp/mongodb/mongodb-1.8.0/src/libmongoc/src/libmongoc/src/ -I/tmp/mongodb/mongodb-1.8.0/src/BSON/ -I/tmp/mongodb/mongodb-1.8.0/src/MongoDB/ -I/tmp/mongodb/mongodb-1.8.0/src/MongoDB/Exception/ -I/tmp/mongodb/mongodb-1.8.0/src/MongoDB/Monitoring/ -I/tmp/mongodb/mongodb-1.8.0/src/contrib/ -DHAVE_CONFIG_H -g -O2 -c /tmp/mongodb/mongodb-1.8.0/php_phongo.c  -fPIC -DPIC -o .libs/php_phongo.o
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c: In function 'php_phongo_dispatch_handlers':
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c:2315:20: warning: passing argument 1 of 'zend_call_method' from incompatible pointer type [-Wincompatible-pointer-types]
2:    zend_call_method(value, NULL, NULL, name, strlen(name), NULL, 1, z_event, NULL);
2:                     ^~~~~
2: In file included from /tmp/mongodb/mongodb-1.8.0/php_phongo.c:27:
2: /usr/local/include/php/Zend/zend_interfaces.h:41:16: note: expected 'zend_object *' {aka 'struct _zend_object *'} but argument is of type 'zval *' {aka 'struct _zval_struct *'}
2:  ZEND_API zval* zend_call_method(zend_object *object, zend_class_entry *obj_ce, zend_function **fn_proxy, const char *function_name, size_t function_name_len, zval *retval, uint32_t param_count, zval* arg1, zval* arg2);
2:                 ^~~~~~~~~~~~~~~~
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c: In function 'php_phongo_command_failed':
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c:2401:52: warning: passing argument 2 of 'zend_update_property_string' from incompatible pointer type [-Wincompatible-pointer-types]
2:   zend_update_property_string(default_exception_ce, &p_event->z_error, ZEND_STRL("message"), tmp_error.message);
2:                                                     ^~~~~~~~~~~~~~~~~
2: In file included from /usr/local/include/php/main/php.h:35,
2:                  from /tmp/mongodb/mongodb-1.8.0/php_phongo.c:22:
2: /usr/local/include/php/Zend/zend_API.h:390:81: note: expected 'zend_object *' {aka 'struct _zend_object *'} but argument is of type 'zval *' {aka 'struct _zval_struct *'}
2:  ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value);
2:                                                                     ~~~~~~~~~~~~~^~~~~~
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c:2402:50: warning: passing argument 2 of 'zend_update_property_long' from incompatible pointer type [-Wincompatible-pointer-types]
2:   zend_update_property_long(default_exception_ce, &p_event->z_error, ZEND_STRL("code"), tmp_error.code);
2:                                                   ^~~~~~~~~~~~~~~~~
2: In file included from /usr/local/include/php/main/php.h:35,
2:                  from /tmp/mongodb/mongodb-1.8.0/php_phongo.c:22:
2: /usr/local/include/php/Zend/zend_API.h:387:79: note: expected 'zend_object *' {aka 'struct _zend_object *'} but argument is of type 'zval *' {aka 'struct _zval_struct *'}
2:  ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
2:                                                                   ~~~~~~~~~~~~~^~~~~~
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c: In function 'php_phongo_extract_handshake_data':
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c:2544:55: error: expected ')' before 'TSRMLS_CC'
2:    phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"%s\" handshake option to be a string, %s given", key, PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(zvalue));
2:                                                        ^~~~~~~~~~
2:                                                        )
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c:2544:3: error: too few arguments to function 'phongo_throw_exception'
2:    phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"%s\" handshake option to be a string, %s given", key, PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(zvalue));
2:    ^~~~~~~~~~~~~~~~~~~~~~
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c:185:6: note: declared here
2:  void phongo_throw_exception(php_phongo_error_domain_t domain, const char* format, ...)
2:       ^~~~~~~~~~~~~~~~~~~~~~
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c: In function 'php_phongo_set_handshake_data':
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c:2619:56: error: expected ')' before 'TSRMLS_CC'
2:     phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"driver\" driver option to be an array, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(driver));
2:                                                         ^~~~~~~~~~
2:                                                         )
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c:2619:4: error: too few arguments to function 'phongo_throw_exception'
2:     phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"driver\" driver option to be an array, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(driver));
2:     ^~~~~~~~~~~~~~~~~~~~~~
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c:185:6: note: declared here
2:  void phongo_throw_exception(php_phongo_error_domain_t domain, const char* format, ...)
2:       ^~~~~~~~~~~~~~~~~~~~~~
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c: In function 'php_phongo_std_get_gc':
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c:3523:33: warning: passing argument 1 of 'zend_std_get_properties' from incompatible pointer type [-Wincompatible-pointer-types]
2:   return zend_std_get_properties(object);
2:                                  ^~~~~~
2: In file included from /usr/local/include/php/Zend/zend.h:366,
2:                  from /usr/local/include/php/main/php.h:31,
2:                  from /tmp/mongodb/mongodb-1.8.0/php_phongo.c:22:
2: /usr/local/include/php/Zend/zend_object_handlers.h:191:21: note: expected 'zend_object *' {aka 'struct _zend_object *'} but argument is of type 'zval *' {aka 'struct _zval_struct *'}
2:  ZEND_API HashTable *zend_std_get_properties(zend_object *object);
2:                      ^~~~~~~~~~~~~~~~~~~~~~~
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c: In function 'zm_startup_mongodb':
2: /tmp/mongodb/mongodb-1.8.0/php_phongo.c:3546:36: warning: assignment to 'zend_object_get_gc_t' {aka 'struct _zend_array * (*)(struct _zend_object *, struct _zval_struct **, int *)'} from incompatible pointer type 'HashTable * (*)(zval *, zval **, int *)' {aka 'struct _zend_array * (*)(struct _zval_struct *, struct _zval_struct **, int *)'} [-Wincompatible-pointer-types]
2:   phongo_std_object_handlers.get_gc = php_phongo_std_get_gc;
2:                                     ^
2: make: *** [Makefile:560: php_phongo.lo] Error 1

Is there something missing on my side or needs the extension some work to run on PHP8?

Thanks for your help!

@jmikola
Copy link
Member

jmikola commented Sep 2, 2020

Support for PHP 8 is currently being tracked in PHPC-1631. It currently doesn't have an estimated completion date, but we definitely plan to release a version of the driver with PHP 8 compatibility before PHP 8.0 itself is tagged.

@rieschl
Copy link
Author

rieschl commented Sep 3, 2020

Support for PHP 8 is currently being tracked in PHPC-1631. It currently doesn't have an estimated completion date, but we definitely plan to release a version of the driver with PHP 8 compatibility before PHP 8.0 itself is tagged.

thanks for the update! for some reason I could not access Jira without login yesterday.

@jmikola
Copy link
Member

jmikola commented Sep 3, 2020

@rieschl: No worries. PHPC-1631 may be private, as it's an epic type (unfortunate internal JIRA policy), but I've linked this GitHub issue to it and will follow up here once it is ultimately resolved.

@nlared
Copy link

nlared commented Sep 20, 2020

I make the same with pecl php 8-beta 3 with the same results

@alcaeus
Copy link
Member

alcaeus commented Sep 21, 2020

@nlared we will post an update once we've got a working version. Future beta or RC releases of PHP 8 won't make this extension work. Due to internal API changes in PHP, we need to update significant portions of the driver, which takes time to ensure that the extension will still compile in all versions of PHP we want to support (most likely PHP 7.0 and newer).

@Jan-E
Copy link

Jan-E commented Oct 23, 2020

The config.w32 needs some changes as well at https://github.com/mongodb/mongo-php-driver/blob/master/config.w32#L70 because JSON is enabled by default now. See php/php-src#5495 (comment) for a possible fix.

  /* Note: ADD_EXTENSION_DEP() cannot be used to declare that we depend on the
   * date and standard extensions. Assume that they're always enabled. */

applies to json in PHP 8 as well.

@cmb69
Copy link
Contributor

cmb69 commented Oct 24, 2020

The fix mentioned by @Jan-E is only necessary before php/php-src@5609701 (available as of PHP 8.0.0RC3, scheduled for Oct, 29th).

@cmb69
Copy link
Contributor

cmb69 commented Oct 24, 2020

I've also submitted php/php-src#6383.

@Jan-E
Copy link

Jan-E commented Oct 24, 2020

The fix mentioned by @Jan-E is only necessary before php/php-src@5609701 (available as of PHP 8.0.0RC3, scheduled for Oct, 29th).

Confirmed. But beware: the fix for ext/standard and ext/date will only be available in PHP 7.3+

@alcaeus
Copy link
Member

alcaeus commented Oct 30, 2020

The fix mentioned by @Jan-E is only necessary before php/php-src@5609701 (available as of PHP 8.0.0RC3, scheduled for Oct, 29th).

Confirmed. But beware: the fix for ext/standard and ext/date will only be available in PHP 7.3+

@Jan-E: is there a way to properly handle this in PHP 7 all the way to PHP 8, or should we leave this as is for the time being?

@cmb69
Copy link
Contributor

cmb69 commented Oct 30, 2020

I think you can use any of the PHP_VERSION variables in config.w32 to conditionally add the dependencies.

@alcaeus
Copy link
Member

alcaeus commented Nov 4, 2020

I've created PHPC-1704 to track the improvements to the Windows build scripts. I'll close out this issue as master compiles against PHP 8. We'll be releasing a beta for 1.9.0 in the coming days, with a stable release coming before the release of PHP 8 later this month. Until the releases happen, people can follow the instructions on building the driver from source to test on PHP 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants