Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Zend/tests/property_hooks/gh25314.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
GH-25314 (Assertion in ZEND_DO_FCALL: reference returned by &__get() reaches property hook TMP result)
--CREDITS--
YuanchengJiang
--FILE--
<?php

class P {
public int $d = 1;
function &__get($name) {}
}
class C extends P {
public int $d = 2 { get => parent::$d::get(); }
}
class GC extends C {
public int $d { get => parent::$d::get(); }
}

var_dump((new GC)->d);

?>
--EXPECTF--
Notice: Only variable references should be returned by reference in %s on line %d

Fatal error: Uncaught TypeError: Value of type null returned from GC::__get() must be compatible with unset property GC::$d of type int in %s:%d
Stack trace:
#0 %s(%d): P->$d::get()
#1 %s(%d): C->$d::get()
#2 %s(%d): GC->$d::get()
#3 {main}
thrown in %s on line %d
8 changes: 6 additions & 2 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1880,11 +1880,15 @@ static ZEND_FUNCTION(zend_parent_hook_get_trampoline)
}

zval rv;
const zval *retval = obj->handlers->read_property(obj, prop_name, BP_VAR_R, NULL, &rv);
zval *retval = obj->handlers->read_property(obj, prop_name, BP_VAR_R, NULL, &rv);
if (retval == &rv) {
RETVAL_COPY_VALUE(retval);
if (UNEXPECTED(Z_ISREF_P(return_value))) {
/* __get() may return by reference. */
zend_unwrap_reference(return_value);
}
} else {
RETVAL_COPY(retval);
RETVAL_COPY_DEREF(retval);
}

clean:
Expand Down
Loading