Skip to content

Initializing array element with reference returned by function not possible #17773

@ohyeaah

Description

@ohyeaah

Description

Please note that when removing the ampersand at line 13 it seems to work but then it's no longer a reference.

<?php
function &moh()
{
  static $o;
  return $o;
}

// works
$jo = [0];
$jo[0] = &moh();

// shows error
$jo = [&moh()];

Resulted in this output:

Fatal error: Can't use function return value in write context in /home/user1/Schreibtisch/test.php on line 13

But I expected this output instead:

PHP Version

PHP 8.4.4

Operating System

3v4l

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions