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

Allow constructor property promotion with final properties #17860

Open
DanielEScherzer opened this issue Feb 19, 2025 · 3 comments
Open

Allow constructor property promotion with final properties #17860

DanielEScherzer opened this issue Feb 19, 2025 · 3 comments

Comments

@DanielEScherzer
Copy link
Contributor

DanielEScherzer commented Feb 19, 2025

Description

The following code (https://3v4l.org/t2Pra)

<?php

class Demo {
    public function __construct(
        final public string $v
    ) {}
}

$d = new Demo( "FOO" );
var_dump( $d );

$r = new ReflectionProperty( Demo::class, 'v' );
var_dump( $r->isFinal() );

Resulted in this output:

Fatal error: Cannot use the final modifier on a parameter in /in/t2Pra on line 5

Process exited with code 255.

But I expected this output instead (from https://3v4l.org/Zus4v)

object(Demo)#1 (1) {
  ["v"]=>
  string(3) "FOO"
}
bool(true)

From discussion on #17861

This came up, and there were some concerns it could imply const parameters as in Java. So we just left it out.

@DanielEScherzer DanielEScherzer changed the title Final properties can use constructor property promotion Final properties cannot use constructor property promotion Feb 19, 2025
DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Feb 19, 2025
@iluuu1994
Copy link
Member

As mentioned in the PR itself, this came up in the discussion and was implicitly not part of the RFC. It's still reasonable to add, but there should be a separate discussion on the ML for it. That might be enough, but people might ask for an RFC (given the feedback, and the reason why we didn't add it in the first place).

@iluuu1994 iluuu1994 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 19, 2025
@DanielEScherzer
Copy link
Contributor Author

As mentioned in the PR itself, this came up in the discussion and was implicitly not part of the RFC. It's still reasonable to add, but there should be a separate discussion on the ML for it. That might be enough, but people might ask for an RFC (given the feedback, and the reason why we didn't add it in the first place).

Okay, so then can this please be re-opened as a feature request? I don't have the rights to re-open the issue. I'll send an email to the mailing list in the next few days

@iluuu1994 iluuu1994 reopened this Feb 21, 2025
@DanielEScherzer DanielEScherzer changed the title Final properties cannot use constructor property promotion Allow constructor property promotion with final properties Feb 21, 2025
@DanielEScherzer
Copy link
Contributor Author

Started mailing list discussion, https://externals.io/message/126475

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