Commit 625f0a7b490 for php.net
commit 625f0a7b49043e7ccf1e4d478cf5324466f1d017
Author: Ilija Tovilo <ilija.tovilo@me.com>
Date: Fri May 29 12:12:52 2026 +0200
Fix ref unwrap for zend_call_method_if_exists() (zend_test) (GH-22179)
Fixes GH-22175
diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c
index 52fe41eb18c..8cb3fe6cba0 100644
--- a/ext/zend_test/test.c
+++ b/ext/zend_test/test.c
@@ -543,6 +543,9 @@ static ZEND_FUNCTION(zend_call_method_if_exists)
}
RETURN_NULL();
}
+ if (Z_TYPE_P(return_value) == IS_REFERENCE) {
+ zend_unwrap_reference(return_value);
+ }
}
static ZEND_FUNCTION(zend_test_call_with_consumed_args)
diff --git a/ext/zend_test/tests/gh22175.phpt b/ext/zend_test/tests/gh22175.phpt
new file mode 100644
index 00000000000..c2db3c9c4e0
--- /dev/null
+++ b/ext/zend_test/tests/gh22175.phpt
@@ -0,0 +1,18 @@
+--TEST--
+GH-22175: zend_call_method_if_exists() must unref return value
+--CREDITS--
+YuanchengJiang
+--EXTENSIONS--
+zend_test
+--FILE--
+<?php
+
+class Foo {
+ public function &test() {}
+}
+
+zend_call_method_if_exists(new Foo, 'test');
+
+?>
+--EXPECTF--
+Notice: Only variable references should be returned by reference in %s on line %d