Skip to content

Commit 7d49189

Browse files
committed
Make C functions returning "void" to return PHP "null" (#10579)
In PHP-8.2 and below we by mistake returned "object(FFI\CData:void)#2 (0) {}". We decided not to fix this in PHP-8.2 and below to avoid BC breaks.
2 parents 10c26ce + 851e462 commit 7d49189

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

ext/ffi/ffi.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -2832,7 +2832,11 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */
28322832
free_alloca(arg_values, arg_values_use_heap);
28332833
}
28342834

2835-
zend_ffi_cdata_to_zval(NULL, ret, ZEND_FFI_TYPE(type->func.ret_type), BP_VAR_R, return_value, 0, 1, 0);
2835+
if (ZEND_FFI_TYPE(type->func.ret_type)->kind != ZEND_FFI_TYPE_VOID) {
2836+
zend_ffi_cdata_to_zval(NULL, ret, ZEND_FFI_TYPE(type->func.ret_type), BP_VAR_R, return_value, 0, 1, 0);
2837+
} else {
2838+
ZVAL_NULL(return_value);
2839+
}
28362840
free_alloca(ret, ret_use_heap);
28372841

28382842
exit:

ext/ffi/tests/gh10568.phpt

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ var_dump($libc->strlen("abc"));
2020
?>
2121
DONE
2222
--EXPECT--
23-
object(FFI\CData:void)#2 (0) {
24-
}
23+
NULL
2524
DONE

0 commit comments

Comments
 (0)