Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

PHP Fatal error: Variadic parameter cannot have a default value #248

Closed
keksa opened this issue Aug 27, 2020 · 4 comments
Closed

PHP Fatal error: Variadic parameter cannot have a default value #248

keksa opened this issue Aug 27, 2020 · 4 comments

Comments

@keksa
Copy link
Contributor

keksa commented Aug 27, 2020

When creating a mock of the following class, phony will crash with Variadic parameter cannot have a default value. The problem is with the ?int ...$statuses definition, without ? there is no crash.

class being mocked

class Foo {
    /**
     * @var int|null
     */
    private $status;

    public function hasStatus(?int ...$statuses): bool
    {
        return in_array($this->status, $statuses, true);
    }
}

phony-generated source of mock

public function hasStatus(
    int ...$a0 = null
) : bool {
    $argumentCount = \func_num_args();
    $arguments = [];


    for ($i = 0; $i < $argumentCount; ++$i) {
        $arguments[] = $a0[$i - 0];
    }

    if (!$this->_handle) {
        $result = parent::hasStatus(...$arguments);

        return $result;
    }

    $result = $this->_handle->spy(__FUNCTION__)->invokeWith(
        new \Eloquent\Phony\Call\Arguments($arguments)
    );

    return $result;
}
@ezzatron
Copy link
Contributor

Thanks for the report, I'll look into it. Which version of PHP are you running, out of interest?

@keksa
Copy link
Contributor Author

keksa commented Aug 28, 2020

Hi @ezzatron, I'm on PHP 7.3.21.

@ezzatron
Copy link
Contributor

Fixed in 4.0.1.

@keksa
Copy link
Contributor Author

keksa commented Aug 31, 2020

@ezzatron Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants