From: Christoph M. Becker Date: Mon, 29 Jun 2020 13:39:17 +0000 (+0200) Subject: Fix #79749: Converting FFI instances to bool fails X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aca621cf926cf86fd186395d3877fc63b65f3d16;p=php Fix #79749: Converting FFI instances to bool fails Casting objects to bool is supposed to yield `true`. Since the `cast_object` handler is required now, we have to implement the `_IS_BOOL` conversion there. --- diff --git a/NEWS b/NEWS index edaf30af76..84e904da44 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,11 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -?? ??? ????, PHP 8.0.0alpha1 +?? ??? ????, PHP 8.0.0alpha2 + +- FFI: + . Fixed bug #79749 (Converting FFI instances to bool fails). (cmb) + +25 Jun 2020, PHP 8.0.0alpha1 - Core: . Removed the pdo_odbc.db2_instance_name php.ini directive. (Kalle) diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 28baf1fd31..946f6c9845 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -1096,6 +1096,9 @@ again: } convert_to_string(writeobj); return SUCCESS; + } else if (type == _IS_BOOL) { + ZVAL_TRUE(writeobj); + return SUCCESS; } return FAILURE; @@ -4642,7 +4645,13 @@ static HashTable *zend_fake_get_gc(zend_object *ob, zval **table, int *n) /* {{{ static int zend_fake_cast_object(zend_object *obj, zval *result, int type) { - return FAILURE; + switch (type) { + case _IS_BOOL: + ZVAL_TRUE(result); + return SUCCESS; + default: + return FAILURE; + } } static ZEND_COLD zend_never_inline void zend_ffi_use_after_free(void) /* {{{ */ diff --git a/ext/ffi/tests/bug79749.phpt b/ext/ffi/tests/bug79749.phpt new file mode 100644 index 0000000000..5e0862a207 --- /dev/null +++ b/ext/ffi/tests/bug79749.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #79749 (Converting FFI instances to bool fails) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(true) +bool(true) +bool(true)