Commit 8084ab369d1 for php

commit 8084ab369d1aacdfccf3244174a7d73551a3466c
Author: Tomasz Kowalczyk <tomasz@kowalczyk.cc>
Date:   Thu Nov 26 19:47:26 2026 +0100

    Fix GH-25779: mysqli_fetch_object() crashes with JIT when the constructor keeps a reference and the result is discarded (#25784)

    mysqli_fetch_object() calls the constructor on the returned object, and the
    constructor can keep a reference to $this. The stub still declared
    @refcount 1, which lets function JIT and tracing JIT destroy the object when
    the result is discarded while that reference still uses it. Drop the
    annotation.

diff --git a/NEWS b/NEWS
index 7766b7462cc..c71a4275fa1 100644
--- a/NEWS
+++ b/NEWS
@@ -116,6 +116,11 @@ PHP                                                                        NEWS
   . Fixed the JIT freeing the string returned by mb_encode_mimeheader() or
     mb_output_handler() while it is still in use. (Ilia Alshanetsky)

+- MySQLi:
+  . Fixed bug GH-25779 (mysqli_fetch_object() crashes with JIT when the
+    constructor keeps a reference and the result is discarded).
+    (Tomasz Kowalczyk)
+
 - Opcache:
   . Fixed bug GH-24801 (JIT: SIGFPE in ir_fold MUL_OV constant folding).
     (waroad)
diff --git a/Zend/Optimizer/zend_func_infos.h b/Zend/Optimizer/zend_func_infos.h
index faff2f43b5c..ce636919301 100644
--- a/Zend/Optimizer/zend_func_infos.h
+++ b/Zend/Optimizer/zend_func_infos.h
@@ -249,7 +249,6 @@ static const func_info_t func_infos[] = {
 	F1("mysqli_fetch_all", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY),
 	F1("mysqli_fetch_array", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_NULL|MAY_BE_FALSE),
 	F1("mysqli_fetch_assoc", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_NULL|MAY_BE_FALSE),
-	F1("mysqli_fetch_object", MAY_BE_OBJECT|MAY_BE_NULL|MAY_BE_FALSE),
 	F1("mysqli_fetch_row", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ANY|MAY_BE_NULL|MAY_BE_FALSE),
 	F1("mysqli_get_connection_stats", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY),
 	F1("mysqli_get_client_stats", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING),
diff --git a/ext/mysqli/mysqli.stub.php b/ext/mysqli/mysqli.stub.php
index de287b347de..23b21556532 100644
--- a/ext/mysqli/mysqli.stub.php
+++ b/ext/mysqli/mysqli.stub.php
@@ -1423,7 +1423,6 @@ function mysqli_fetch_array(mysqli_result $result, int $mode = MYSQLI_BOTH): arr
  */
 function mysqli_fetch_assoc(mysqli_result $result): array|null|false {}

-/** @refcount 1 */
 function mysqli_fetch_object(mysqli_result $result, string $class = "stdClass", array $constructor_args = []): object|null|false {}

 /**
diff --git a/ext/mysqli/mysqli_arginfo.h b/ext/mysqli/mysqli_arginfo.h
index e45c3550a6c..636ee9a5dfc 100644
Binary files a/ext/mysqli/mysqli_arginfo.h and b/ext/mysqli/mysqli_arginfo.h differ
diff --git a/ext/mysqli/tests/gh25779.phpt b/ext/mysqli/tests/gh25779.phpt
new file mode 100644
index 00000000000..d89f8deb180
--- /dev/null
+++ b/ext/mysqli/tests/gh25779.phpt
@@ -0,0 +1,47 @@
+--TEST--
+GH-25779: mysqli_fetch_object() crashes with JIT when the constructor keeps a reference and the result is discarded
+--EXTENSIONS--
+mysqli
+opcache
+--SKIPIF--
+<?php
+require_once __DIR__ . '/test_setup/test_helpers.inc';
+mysqli_check_skip_test();
+?>
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.jit=function
+opcache.jit_buffer_size=64M
+opcache.file_update_protection=0
+--FILE--
+<?php
+require_once __DIR__ . '/test_setup/test_helpers.inc';
+
+class Row {
+    public static array $rows = [];
+
+    public function __construct() {
+        self::$rows[] = $this;
+    }
+
+    public function __destruct() { echo "destruct\n"; }
+}
+
+function test(mysqli_result $result) {
+    mysqli_fetch_object($result, Row::class);
+}
+
+$link = default_mysqli_connect();
+test(mysqli_query($link, "SELECT 1 AS id"));
+var_dump(Row::$rows);
+?>
+--EXPECTF--
+array(1) {
+  [0]=>
+  object(Row)#%d (1) {
+    ["id"]=>
+    string(1) "1"
+  }
+}
+destruct