Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mvorisek opened this issue Sep 1, 2023 · 3 comments
Closed

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

mvorisek opened this issue Sep 1, 2023 · 3 comments

Comments

@mvorisek
Copy link
Contributor

mvorisek commented Sep 1, 2023

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

@mvorisek
Copy link
Contributor Author

mvorisek commented Sep 1, 2023

it seems:

createAnd(func_get_args()[0]);

compiles, but:

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

and

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

does not

@KapitanOczywisty
Copy link

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.

@mvorisek
Copy link
Contributor Author

mvorisek commented Sep 1, 2023

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

Seems like a parser limitation.

iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Sep 6, 2023
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Sep 6, 2023
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Sep 6, 2023
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Sep 6, 2023
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Sep 6, 2023
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Sep 6, 2023
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Sep 6, 2023
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants