Skip to content

Commit aca621c

Browse files
committed
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.
1 parent 6e1990d commit aca621c

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

NEWS

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3-
?? ??? ????, PHP 8.0.0alpha1
3+
?? ??? ????, PHP 8.0.0alpha2
4+
5+
- FFI:
6+
. Fixed bug #79749 (Converting FFI instances to bool fails). (cmb)
7+
8+
25 Jun 2020, PHP 8.0.0alpha1
49

510
- Core:
611
. Removed the pdo_odbc.db2_instance_name php.ini directive. (Kalle)

ext/ffi/ffi.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,9 @@ static int zend_ffi_cdata_cast_object(zend_object *readobj, zval *writeobj, int
10961096
}
10971097
convert_to_string(writeobj);
10981098
return SUCCESS;
1099+
} else if (type == _IS_BOOL) {
1100+
ZVAL_TRUE(writeobj);
1101+
return SUCCESS;
10991102
}
11001103

11011104
return FAILURE;
@@ -4642,7 +4645,13 @@ static HashTable *zend_fake_get_gc(zend_object *ob, zval **table, int *n) /* {{{
46424645

46434646
static int zend_fake_cast_object(zend_object *obj, zval *result, int type)
46444647
{
4645-
return FAILURE;
4648+
switch (type) {
4649+
case _IS_BOOL:
4650+
ZVAL_TRUE(result);
4651+
return SUCCESS;
4652+
default:
4653+
return FAILURE;
4654+
}
46464655
}
46474656

46484657
static ZEND_COLD zend_never_inline void zend_ffi_use_after_free(void) /* {{{ */

ext/ffi/tests/bug79749.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #79749 (Converting FFI instances to bool fails)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('ffi')) die('skip ffi extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$ffi = FFI::cdef('typedef int dummy;');
10+
var_dump((bool) $ffi);
11+
var_dump((bool) FFI::type('int'));
12+
var_dump((bool) FFI::new('int'));
13+
?>
14+
--EXPECT--
15+
bool(true)
16+
bool(true)
17+
bool(true)

0 commit comments

Comments
 (0)