Skip to content

Support property hooks in promoted parameters#64

Merged
thekid merged 1 commit into
masterfrom
feature/promoted-hooks
Jul 5, 2026
Merged

Support property hooks in promoted parameters#64
thekid merged 1 commit into
masterfrom
feature/promoted-hooks

Conversation

@thekid

@thekid thekid commented Jul 5, 2026

Copy link
Copy Markdown
Member

See https://wiki.php.net/rfc/property-hooks#interaction_with_constructor_property_promotion

class User {
  public function __construct(
    public string $username { set => strtolower($value); }
  ) { }
}

Requires this patch to the compiler - meaning this is a BC break, and will result in a major release.

diff --git a/src/main/php/lang/ast/emit/PHP.class.php b/src/main/php/lang/ast/emit/PHP.class.php
index 163ff27..742f531 100755
--- a/src/main/php/lang/ast/emit/PHP.class.php
+++ b/src/main/php/lang/ast/emit/PHP.class.php
@@ -763,8 +763,8 @@ abstract class PHP extends Emitter {
     }

     foreach ($promoted as $param) {
-      $this->emitProperty($result, new Property(
-        is_array($param->promote) ? $param->promote : explode(' ', $param->promote),
+      $this->emitProperty($result, $param->promote instanceof Property ? $param->promote : new Property(
+        $param->promote,
         $param->name,
         $param->type
       ));

@thekid thekid merged commit e3a45d7 into master Jul 5, 2026
16 checks passed
@thekid thekid deleted the feature/promoted-hooks branch July 5, 2026 15:29
@thekid

thekid commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

thekid added a commit to xp-framework/compiler that referenced this pull request Jul 5, 2026
thekid added a commit to xp-framework/reflection that referenced this pull request Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant