Assertion in ZEND_DO_FCALL: reference returned by &__get() reaches property hook TMP result
Description
The following code:
<?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);
Resulted in this output:
php: Zend/zend_vm_execute.h:2172: const zend_op *ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER(zend_execute_data *, const zend_op *): Assertion `opline->result_type != (1<<1) || !(zval_get_type(&(*(ret))) == 10)' failed.
Aborted (core dumped)
To reproduce: ./sapi/cli/php test.php
Commit:
33a61f765a94e018a8d55d962a73e8c8331ee256
Configurations:
CC="clang-12" CXX="clang++-12" CFLAGS="-DZEND_VERIFY_TYPE_INFERENCE" CXXFLAGS="-DZEND_VERIFY_TYPE_INFERENCE" ./configure --enable-debug --enable-address-sanitizer --enable-undefined-sanitizer --enable-re2c-cgoto --enable-zts --enable-bcmath --enable-calendar --enable-dba --enable-dl-test --enable-exif --enable-ftp --enable-gd --enable-gd-jis-conv --enable-mbstring --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-zend-test --with-zlib --with-bz2 --with-curl --with-enchant --with-gettext --with-gmp --with-mhash --with-ldap --with-libedit --with-readline --with-snmp --with-sodium --with-xsl --with-zip --with-mysqli --with-pdo-mysql --with-pdo-pgsql --with-pgsql --with-sqlite3 --with-pdo-sqlite --with-webp --with-jpeg --with-freetype --enable-sigchild --with-pcre-jit --with-iconv
Operating System:
Ubuntu 20.04 Host, Docker 0599jiangyc/flowfusion:latest
This report is automatically generated by FlowFusion
PHP Version
nightly
Operating System
No response
Only reproduces in 8.6+.
Hi, while re-testing property hook trampolines on 8.5.13 (46bcb661d) I can confirm this defect is still present in the 8.5 stable line, in a form the official test does not catch. The gh25314.phpt passes on release builds because a TypeError masks the defect path before it is reached (the assert is debug-only).
With a non-typed hook and a &__get() that returns an object from a static array, the value returned through the parent hook get trampoline (zend_object_handlers.c:1840-1845, RETVAL_COPY without deref) is silently detached, so writes through $x land on a copy and the original data is lost:
class P { static $v = ['k' => 'sensitivedata'];
function &__get($name) { return self::$v; } }
class C extends P { public $d = 2 { get => parent::$d::get(); } }
class GC extends C { public $d { get => parent::$d::get(); } }
$x = (new GC)->d; // should be a reference to P::$v
$x['injected'] = 'X'; // lands on a detached copy
var_dump($x); // ["injected"]=> "X" -- the original "k" is gone
var_dump(P::$v); // unchanged
The fix on master (9afb81f60) is not in 8.5.13. Hope this helps.
@lhjnano Your reproducer triggers an error on 8.6 & 8.5:
Fatal error: Cannot specify default value for virtual hooked property C::$d in x.php on line 4
Please provide a working reproducer.
Hi Nora,
Thanks - you are right. The = 2 default value on the get-only hooked property was unintentionally left in from an earlier variant of the reproducer, and it is exactly what trips the "Cannot specify default value for virtual hooked property" check on the branch heads. Here is a default-free version; this is also the form I would like to ask about.
<?php
class P {
public $d = 1;
static $v = ['k' => 'sensitivedata'];
function &__get($name) { return self::$v; }
}
class C extends P {
public $d { get => parent::$d::get(); }
}
class GC extends C {
public $d { get => parent::$d::get(); }
}
$x = (new GC)->d; // trampoline: parent::$d::get() twice, ending at the &__get() reference
$x['injected'] = 'X';
var_dump($x);
var_dump(P::$v);
Observed (release-style builds: ./configure --disable-all --enable-cli), all on 2026-11-22:
- PHP 8.5.13 (46bcb661d): runs without error.
$xends up asarray(1) { ["injected"]=> "X" }- the original"k"is silently missing from the returned value - andP::$vis untouched (["k"]only). The write did not go through the reference and the read did not return the referenced value. - PHP-8.5 head (e8585b83f, 8.5.14-dev): same silent loss.
- master (d190cfef8, 8.7.0-dev, includes 9afb81f60): same silent loss.
So on 8.5 stable the write-through failure through the parent hook trampoline still reproduces after your fix removed the assertion/UAF symptom; on master the same script no longer crashes but the value returned through the parent::$d::get() chain is an empty array rather than the referenced ['k']. Could you confirm whether losing the referenced value through parent::$prop::get() chains is intended post-9afb81f60, or a remaining gap of this issue?
If it is useful as a separate report: the value loss through parent::$prop::get() also reproduces without any __get() involvement, on a plain parent property, in a two-line hierarchy:
<?php
class P { public $d = 1; }
class C extends P { public $d { get => parent::$d::get(); } }
var_dump((new C)->d); // NULL on 8.5.13 / PHP-8.5 head / PHP-8.6 head / master - expected int(1)
and with a declared default on the child, parent::$d::get() returns the child's default instead of the parent's value (public $d = 9 { get => parent::$d::get() + 100; } gives int(109) instead of int(101)). I can file that separately if you prefer.
Sounds good - we won't file the parent::$prop::get() value-loss observation separately; whether it deserves its own issue is up to you.
All the reproducers above (the default-free version, the two-level variant, and the + 100 variant that shows parent::$d::get() resolving to the child's declared default instead of the parent's value) are self-contained, so feel free to use them when working on the general fix. Thanks for looking into it.