Skip to content

PHP 8.3 | Incorrect error when using static on parameter in extended class #12069

Closed
@jrfnl

Description

@jrfnl

Description

The following code:

<?php

class Foo {
    protected function doSomething(Reflection $a) {
        return true;
    }
}

class Bar extends Foo {
    protected function doSomething(static $b) {
        return true;
    }
}

$obj = new Bar;

PHP 8.0 - 8.2: https://3v4l.org/c5r5q
PHP 8.3: https://3v4l.org/c5r5q/rfc#vgit.master

Resulted in this output:

Fatal error: Cannot use the static modifier on a promoted property in /in/c5r5q on line 10

But I expected this output instead:

Parse error: syntax error, unexpected token "static", expecting variable in /in/c5r5q on line 10

As this method is not a class constructor, the reference to promoted properties is confusing.

Discovered by accident while creating a code sample to test something else completely.

PHP Version

PHP 8.3.0-dev

Operating System

No response

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