Skip to content

Instantly share code, notes, and snippets.

@nielsdos
Created June 6, 2024 18:45
Show Gist options
  • Save nielsdos/f519a9c1b019a83871313cd6e6de29f7 to your computer and use it in GitHub Desktop.
Save nielsdos/f519a9c1b019a83871313cd6e6de29f7 to your computer and use it in GitHub Desktop.
diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c
index 7ba9abd193..c779f0351e 100644
--- a/ext/zend_test/test.c
+++ b/ext/zend_test/test.c
@@ -1057,26 +1057,14 @@ static ZEND_METHOD(_ZendTestClass, returnByRefIntProp)
ZEND_ASSERT(int_prop);
ZEND_ASSERT(!Z_ISERROR_P(int_prop));
- /* Copied from zend_assign_to_variable_reference() */
- zend_reference *ref;
-
- if (EXPECTED(!Z_ISREF_P(int_prop))) {
- ZVAL_NEW_REF(int_prop, int_prop);
- }
- //else if (UNEXPECTED(return_value == int_prop)) {
- // return;
- //}
-
- ref = Z_REF_P(int_prop);
- GC_ADDREF(ref);
- if (Z_REFCOUNTED_P(return_value)) {
- zend_refcounted *garbage = NULL;
- garbage = Z_COUNTED_P(return_value);
- if (garbage) {
- GC_DTOR(garbage);
- }
+ if (!Z_ISREF_P(int_prop)) {
+ zend_property_info *prop_info = zend_get_property_info_for_slot(obj, int_prop);
+ ZEND_ASSERT(ZEND_TYPE_IS_SET(prop_info->type));
+ ZVAL_MAKE_REF(int_prop);
+ ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(int_prop), prop_info);
}
- ZVAL_REF(return_value, ref);
+
+ ZVAL_COPY(return_value, int_prop);
}
// Returns a newly allocated DNF type `Iterator|(Traversable&Countable)`.
diff --git a/ext/zend_test/tests/gen_stub_test_return_by_ref.phpt b/ext/zend_test/tests/gen_stub_test_return_by_ref.phpt
index 26f3150e7c..3b3f59672a 100644
--- a/ext/zend_test/tests/gen_stub_test_return_by_ref.phpt
+++ b/ext/zend_test/tests/gen_stub_test_return_by_ref.phpt
@@ -1,7 +1,5 @@
--TEST--
gen_stub.php: Test that return by ref flag is set
---XFAIL--
-Does not work currently
--EXTENSIONS--
zend_test
--FILE--
@@ -10,9 +8,10 @@
$reflectionMethod = new ReflectionMethod(_ZendTestClass::class, "returnByRefIntProp");
var_dump($reflectionMethod->returnsReference());
+
$o = new _ZendTestClass();
var_dump($o);
-$i = $o->returnByRefIntProp();
+$i =& $o->returnByRefIntProp();
var_dump($i);
$i = 24;
var_dump($i);
@@ -39,7 +38,7 @@
int(24)
object(_ZendTestClass)#2 (3) {
["intProp"]=>
- int(24)
+ &int(24)
["classProp"]=>
NULL
["classUnionProp"]=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment