Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromphp/php-src

Commit02ba9d7

Browse files
committed
Unwrap reference returns in cufa etc
1 parente63443d commit02ba9d7

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
When performing a dynamic call to a ret-by-ref function, the reference should be unwrapped
3+
--FILE--
4+
<?php
5+
6+
namespaceFoo;
7+
8+
function &retRef($x) {
9+
return$x;
10+
}
11+
12+
var_dump(call_user_func('Foo\retRef',42));
13+
var_dump(call_user_func_array('Foo\retRef', [42]));
14+
15+
$closure =function &($x) {
16+
return$x;
17+
};
18+
var_dump($closure->call(newclass {},42));
19+
20+
var_dump((new \ReflectionFunction('Foo\retRef'))->invoke(42));
21+
var_dump((new \ReflectionFunction('Foo\retRef'))->invokeArgs([42]));
22+
23+
class Bar {
24+
function &method($x) {
25+
return$x;
26+
}
27+
}
28+
var_dump((new \ReflectionMethod('Foo\Bar','method'))->invoke(newBar,42));
29+
var_dump((new \ReflectionMethod('Foo\Bar','method'))->invokeArgs(newBar, [42]));
30+
31+
?>
32+
--EXPECT--
33+
int(42)
34+
int(42)
35+
int(42)
36+
int(42)
37+
int(42)
38+
int(42)
39+
int(42)

‎Zend/zend_closures.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ ZEND_METHOD(Closure, call)
166166
}
167167

168168
if (zend_call_function(&fci,&fci_cache)==SUCCESS&&Z_TYPE(closure_result)!=IS_UNDEF) {
169+
if (Z_ISREF(closure_result)) {
170+
zend_unwrap_reference(&closure_result);
171+
}
169172
ZVAL_COPY_VALUE(return_value,&closure_result);
170173
}
171174

‎ext/reflection/php_reflection.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,9 @@ ZEND_METHOD(reflection_function, invoke)
19851985
}
19861986

19871987
if (Z_TYPE(retval)!=IS_UNDEF) {
1988+
if (Z_ISREF(retval)) {
1989+
zend_unwrap_reference(&retval);
1990+
}
19881991
ZVAL_COPY_VALUE(return_value,&retval);
19891992
}
19901993
}
@@ -2048,6 +2051,9 @@ ZEND_METHOD(reflection_function, invokeArgs)
20482051
}
20492052

20502053
if (Z_TYPE(retval)!=IS_UNDEF) {
2054+
if (Z_ISREF(retval)) {
2055+
zend_unwrap_reference(&retval);
2056+
}
20512057
ZVAL_COPY_VALUE(return_value,&retval);
20522058
}
20532059
}
@@ -3323,6 +3329,9 @@ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, int variadic)
33233329
}
33243330

33253331
if (Z_TYPE(retval)!=IS_UNDEF) {
3332+
if (Z_ISREF(retval)) {
3333+
zend_unwrap_reference(&retval);
3334+
}
33263335
ZVAL_COPY_VALUE(return_value,&retval);
33273336
}
33283337
}

‎ext/standard/basic_functions.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4823,6 +4823,9 @@ PHP_FUNCTION(call_user_func)
48234823
fci.retval=&retval;
48244824

48254825
if (zend_call_function(&fci,&fci_cache)==SUCCESS&&Z_TYPE(retval)!=IS_UNDEF) {
4826+
if (Z_ISREF(retval)) {
4827+
zend_unwrap_reference(&retval);
4828+
}
48264829
ZVAL_COPY_VALUE(return_value,&retval);
48274830
}
48284831
}
@@ -4846,6 +4849,9 @@ PHP_FUNCTION(call_user_func_array)
48464849
fci.retval=&retval;
48474850

48484851
if (zend_call_function(&fci,&fci_cache)==SUCCESS&&Z_TYPE(retval)!=IS_UNDEF) {
4852+
if (Z_ISREF(retval)) {
4853+
zend_unwrap_reference(&retval);
4854+
}
48494855
ZVAL_COPY_VALUE(return_value,&retval);
48504856
}
48514857

@@ -4880,6 +4886,9 @@ PHP_FUNCTION(forward_static_call)
48804886
}
48814887

48824888
if (zend_call_function(&fci,&fci_cache)==SUCCESS&&Z_TYPE(retval)!=IS_UNDEF) {
4889+
if (Z_ISREF(retval)) {
4890+
zend_unwrap_reference(&retval);
4891+
}
48834892
ZVAL_COPY_VALUE(return_value,&retval);
48844893
}
48854894
}
@@ -4908,6 +4917,9 @@ PHP_FUNCTION(forward_static_call_array)
49084917
}
49094918

49104919
if (zend_call_function(&fci,&fci_cache)==SUCCESS&&Z_TYPE(retval)!=IS_UNDEF) {
4920+
if (Z_ISREF(retval)) {
4921+
zend_unwrap_reference(&retval);
4922+
}
49114923
ZVAL_COPY_VALUE(return_value,&retval);
49124924
}
49134925

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp