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

Implement property hooks syntax #45

Merged
merged 20 commits into from
Jun 15, 2024
Merged

Implement property hooks syntax #45

merged 20 commits into from
Jun 15, 2024

Conversation

thekid
Copy link
Member

@thekid thekid commented May 9, 2023

This pull request adds syntactic support for property hooks.

  • Braced forms: get, set { <statements> }
  • Abbreviated forms: get, set => <expr>
  • Abbreviated getter: $prop => <expr>
  • Specifying the argument name: set($value)
  • Specifying the argument type: set(string $value)
  • Final hooks: final get|set
  • Abstract hooks set; get; (see here)
  • References - see https://externals.io/message/120213#120362
class Person {
  public $modified= false;

  public $name {
    set {
      $this->name= $value;
      $this->modified= true;
    }
  }
}

$p= new Person();
$p->name= 'Test';
$p->modified; // true

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

@@ -3,6 +3,7 @@
class Property extends Annotated implements Member {
public $kind= 'property';
public $name, $modifiers, $expression, $type, $holder;
public $hooks= null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not adding this as constructor parameter partly in order to prevent a BC break, partly because of how parsing works.

@thekid
Copy link
Member Author

thekid commented May 7, 2024

The RFC has been accepted, however php/php-src#13455 isn't merged at the time of writing, so we don't have a reference implementation quite ready yet for testing this thorougly.

@thekid thekid merged commit 5003111 into master Jun 15, 2024
12 checks passed
@thekid thekid deleted the feature/property-hooks branch June 15, 2024 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant