Skip to content

PHP 8 | 'static' is an invalid class name #527

@AlexandruGG

Description

@AlexandruGG

Hello, I'm seeing a fatal error trying to use Prophecy with PHPUnit in a Symfony 5 project running PHP 8 with the new static return type. Here is the error:

PHP Fatal error:  '\static' is an invalid class name in /Users/alex/dev/project/vendor/bin/.phpunit/phpunit-9.5-0/vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(49) : eval()'d code on line 11

And a simplified version of the Entity I'm trying to create a prophecy for:

class MyEntity {
    /**
     * @ORM\Column(name="id", type="integer", nullable=false, options={"unsigned"=true})
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private int $id;

    /**
     * @ORM\Column(name="name", type="string", length=50, nullable=false)
     */
    private string $name;

    public function getId(): int
    {
        return $this->id;
    }

    public function getName(): string
    {
        return $this->name;
    }

    public function setName(string $name): static // <--- if I replace this with 'self' it works
    {
        $this->name = $name;

        return $this;
    }
}

Is this a known issue with PHP 8? Apologies if so but I couldn't find any mention of it.

Or am I doing something wrong with this usage?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions