Skip to content

OPcache optimizer (pass 4): dim fetch on by-ref function result passed as argument yields NULL in 8.6.0RC7 #25449

Closed

Description

@pict0r

With OPcache enabled, an array element of a by-reference function's return value, passed directly as a function
argument, arrives as null (with the warning "Trying to access array offset on array").
It works without OPcache, with opcache.optimization_level=0x7FFEBFF7 (pass 4 disabled), and on PHP 8.5.4.

The following code:

<?php
declare(strict_types=1);
function &registry(): array { static $r = ['back' => '']; return $r; }
function set(string $a): void { $r = &registry(); $r['back'] = $a; }
function direct(): string { return json_encode(menu(registry()['back'])); }
function menu(string $w = ''): array { return [$w]; }
set('/x');
echo direct(), "\n";

Run with:

php -d opcache.enable_cli=1 -d opcache.file_update_protection=0 test.php

Resulted in this output:

Warning: Trying to access array offset on array in test.php on line 5

Fatal error: Uncaught TypeError: menu(): Argument #1 ($w) must be of type string, null given, called in test.php on line 5

But I expected this output instead:

["\/x"]

Also affected: static and instance methods returning by reference (consume(K::refStatic()['k']), consume($o->refMethod()['k'])),
regardless of whether the callee is declared before or after the call. Not affected: by-value functions, assigning the
element to a variable first, or registry()['k'] ?? null.

Activity

  1. self-assigned this
    on Nov 14, 2026
  2. added a commit that references this issue on Nov 22, 2026
    95cacec
  3. added a commit that references this issue on Nov 22, 2026
    12d9e40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions