]> granicus.if.org Git - php/commitdiff
Fix #79749: Converting FFI instances to bool fails
authorChristoph M. Becker <cmbecker69@gmx.de>
Mon, 29 Jun 2020 13:39:17 +0000 (15:39 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Mon, 29 Jun 2020 14:02:58 +0000 (16:02 +0200)
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.

NEWS
ext/ffi/ffi.c
ext/ffi/tests/bug79749.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index edaf30af76b78b0dd0a7bdf3ea70c043dd9f3332..84e904da44325a08bf99332753eeaa3bd0691961 100644 (file)
--- 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)
index 28baf1fd31c7810ed368b8b38469194a70514bd0..946f6c984529975a661126801189cc83605ec05a 100644 (file)
@@ -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 (file)
index 0000000..5e0862a
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Bug #79749 (Converting FFI instances to bool fails)
+--SKIPIF--
+<?php
+if (!extension_loaded('ffi')) die('skip ffi extension not available');
+?>
+--FILE--
+<?php
+$ffi = FFI::cdef('typedef int dummy;');
+var_dump((bool) $ffi);
+var_dump((bool) FFI::type('int'));
+var_dump((bool) FFI::new('int'));
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)