Commit e9b7b601476 for php

commit e9b7b601476e84ca3313f0bf64b9779a18eadf36
Author: DPDmancul <davide.peressoni@tuta.io>
Date:   Wed Nov 18 16:10:22 2026 +0100

    Fix GH-25558: FFI: struct with an enum field passed by value is described to libffi with a void element

    Closes GH-25560.

diff --git a/NEWS b/NEWS
index 7405d2f6ac0..1a77a3e71e3 100644
--- a/NEWS
+++ b/NEWS
@@ -68,6 +68,10 @@ PHP                                                                        NEWS
   . Fixed use-after-free in getElementById() after a removed ID attribute is
     freed. (Ilia Alshanetsky)

+- FFI:
+  . Fixed bug GH-25558 (struct with an enum field passed by value is described
+    to libffi with a void element). (Davide Peressoni)
+
 - Filter:
   . Fixed stack overflow in filter_var() and filter_var_array() with deeply
     nested arrays. (Eyüp Can Akman)
diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c
index 73e738202c8..06f564c2e7e 100644
--- a/ext/ffi/ffi.c
+++ b/ext/ffi/ffi.c
@@ -359,7 +359,11 @@ static ffi_type* zend_ffi_face_struct_add_fields(ffi_type* t, zend_ffi_type *typ
 	zend_ffi_field *field;

 	ZEND_HASH_MAP_FOREACH_PTR(&type->record.fields, field) {
-		switch (ZEND_FFI_TYPE(field->type)->kind) {
+		zend_ffi_type_kind field_kind = ZEND_FFI_TYPE(field->type)->kind;
+		if (field_kind == ZEND_FFI_TYPE_ENUM) {
+			field_kind = ZEND_FFI_TYPE(field->type)->enumeration.kind;
+		}
+		switch (field_kind) {
 			case ZEND_FFI_TYPE_FLOAT:
 				t->elements[(*i)++] = &ffi_type_float;
 				break;
diff --git a/ext/ffi/tests/bug25558.phpt b/ext/ffi/tests/bug25558.phpt
new file mode 100644
index 00000000000..815bc5a66ba
--- /dev/null
+++ b/ext/ffi/tests/bug25558.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Bug #25558 (FFI: struct with an enum field passed by value is described to libffi with a void element)
+--EXTENSIONS--
+ffi
+--INI--
+ffi.enable=1
+--FILE--
+<?php
+
+$ffi = FFI::cdef(<<<EOF
+    typedef enum {
+        RED = 0,
+        GREEN = 1
+    } color;
+
+    typedef struct {
+        char a;
+        color b;
+        char c;
+    } test;
+
+    typedef struct {
+        int (*read_b)(test x);
+        char (*read_c)(test x);
+    } functions;
+    EOF,
+);
+
+$functions = $ffi->new('functions');
+
+$functions->read_b = fn ($x) => $x->b;
+$functions->read_c = fn ($x) => $x->c;
+
+$test = $ffi->new('test');
+$test->a = 2;
+$test->b = $ffi->GREEN;
+$test->c = 3;
+
+var_dump(($functions->read_b)($test));
+var_dump((int)($functions->read_c)($test));
+
+?>
+--EXPECT--
+int(1)
+int(3)