Skip to content

Allow constructor property promotion with final properties #17860

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

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

Allow constructor property promotion with final properties #17860

DanielEScherzer opened this issue Feb 19, 2025 · 8 comments

Comments

@DanielEScherzer
Copy link
Member

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
Member 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
Member Author

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

@DanielEScherzer
Copy link
Member 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

[bolding added] @iluuu1994 given the lack of objections on the mailing list (no one else has asked for an RFC) are you okay with this moving forward without an RFC? If yes, can you please removed the Status: Requires RFC label (I don't have permission to edit labels). If not, can you reply on the mailing list for visibility, and I'll start writing an RFC?

@iluuu1994
Copy link
Member

@DanielEScherzer I think the wording in the e-mail could have been more explicit. Something like:

Unless somebody objects, maintainers have agreed to merge this PR in n weeks.

That leaves no room for interpretation, and it forces people who object to actually engage. Given that there is ample time until feature freeze, do you mind sending another e-mail? 2 weeks should be enough.

@iluuu1994
Copy link
Member

are you okay with this moving forward without an RFC?

But yes, to answer that question, I don't object to move forward without an RFC if nobody else does.

@DanielEScherzer
Copy link
Member Author

Sent an update, I'll be back in 2 weeks

@iluuu1994
Copy link
Member

Thank you @DanielEScherzer!

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