Skip to content

Hooks on constructor promoted properties without visibility are ignored #15438

Closed

Description

@iluuu1994

Description

The following code:

class C {
    public function __construct(
        $prop { set => $value * 2; },
    ) {}
}

$c = new C(42);
var_dump($c);

Resulted in this output:

object(C)#1 (0) {
}

But I expected this output instead:

object(C)#1 (1) {
  ["prop"]=>
  int(84)
}

Or compile error

PHP Version

master

Operating System

No response

Activity

  1. self-assigned this
    on Aug 16, 2024
  2. SerafimArts commented on Aug 16, 2024

    @SerafimArts
    Contributor

    Shouldn't promoted properties have visibility? In this case it's not a promoted property, but a normal constructor argument to which properties (hooks) cannot be applied. IMHO

  3. iluuu1994 commented on Aug 16, 2024

    @iluuu1994
    MemberAuthor

    Not necessarily. readonly is a valid cpp modifier.

  4. SerafimArts commented on Aug 16, 2024

    @SerafimArts
    Contributor

    Got it, then the presence of properties (hooks) as well as access modifiers makes the arguments a promoted property. Didn't think about that, thanks

  5. added a commit that references this issue on Aug 19, 2024
    770616b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions