Skip to content

Commit 625f0a7

Browse files
authored
Fix ref unwrap for zend_call_method_if_exists() (zend_test) (phpGH-22179)
Fixes phpGH-22175
1 parent f9d6735 commit 625f0a7

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

ext/zend_test/test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,9 @@ static ZEND_FUNCTION(zend_call_method_if_exists)
543543
}
544544
RETURN_NULL();
545545
}
546+
if (Z_TYPE_P(return_value) == IS_REFERENCE) {
547+
zend_unwrap_reference(return_value);
548+
}
546549
}
547550

548551
static ZEND_FUNCTION(zend_test_call_with_consumed_args)

ext/zend_test/tests/gh22175.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-22175: zend_call_method_if_exists() must unref return value
3+
--CREDITS--
4+
YuanchengJiang
5+
--EXTENSIONS--
6+
zend_test
7+
--FILE--
8+
<?php
9+
10+
class Foo {
11+
public function &test() {}
12+
}
13+
14+
zend_call_method_if_exists(new Foo, 'test');
15+
16+
?>
17+
--EXPECTF--
18+
Notice: Only variable references should be returned by reference in %s on line %d

0 commit comments

Comments
 (0)