Skip to content

Fatal error: Cannot use result of built-in function in write context #12102

Closed

Description

@mvorisek

Description

The following code:

repro: https://3v4l.org/E8CsC

<?php

class Cl {
    public static function createAnd(...$args)
    {
        var_dump($args);
    }
    
    public function bar()
    {
        static::createAnd(func_get_args()[0]);
    }
}

(new Cl())->bar('y');

Resulted in this output:

Fatal error: Cannot use result of built-in function in write context

But I expected this output instead:

array(1) {
  [0]=>
  string(1) "y"
}

the 3v4l repro shows the issue is present only in some cases, when the same code is in non-class AST, it works

(func_get_args()[0] should return the 1st argument, it is simplified repro from more complex usecase)

PHP Version

any

Operating System

any

Activity

  1. mvorisek commented on Sep 1, 2023

    @mvorisek
    ContributorAuthor

    it seems:

    createAnd(func_get_args()[0]);
    

    compiles, but:

    static::createAnd(func_get_args()[0]);
    

    and

    $this->createAnd(func_get_args()[0]);
    

    does not

  2. KapitanOczywisty commented on Sep 1, 2023

    @KapitanOczywisty

    self::createAnd(func_get_args()[0]); also works. Possibly it's assuming that extending class could have reference there, though i don't think this is technically possible with variadic method.

  3. mvorisek commented on Sep 1, 2023

    @mvorisek
    ContributorAuthor

    Even with static:: and final class/method :)

    Seems like a parser limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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