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

Support PHP 8.4 property hooks #731

Closed
1 of 2 tasks
jnoordsij opened this issue Nov 26, 2024 · 5 comments
Closed
1 of 2 tasks

Support PHP 8.4 property hooks #731

jnoordsij opened this issue Nov 26, 2024 · 5 comments

Comments

@jnoordsij
Copy link

Is your feature request related to a problem?

Describe the solution you'd like

PHP 8.4 has been recently released, introducing property hooks which allows for easier customization to get and set logic of properties.

This new syntax yields some errors when linted with current setup. A small example I've created:

<?php

namespace Foo;

class Foo
{
    private string $privateBar = 'bar';

    public string $bar {
        get => $this->privateBar;
        set(string $bar) {
            $this->privateBar = $bar;
        }
    }
}

When running phpcs --standard=PSR12 foo.php this yields

FILE: ...foo.php
------------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 4 LINES
------------------------------------------------------------------------------
  9 | ERROR | There must not be more than one property declared per statement
 10 | ERROR | Visibility must be declared on property "$this"
 11 | ERROR | There must not be more than one property declared per statement
 11 | ERROR | Visibility must be declared on property "$bar"
 12 | ERROR | There must not be more than one property declared per statement
 12 | ERROR | Visibility must be declared on property "$this"
------------------------------------------------------------------------------

I'd expect no errors linting this.

Additional context (optional)

There might be additional new PHP 8.4 syntax that require additional changes. Maybe this should be listed on #106 or a new tracking issue for PHP 8.4 syntax? I could not find an existing source for tracking 8.4 compatibility.

@jrfnl
Copy link
Member

jrfnl commented Nov 26, 2024

@jnoordsij Thanks for the reminder, yes, I should open a PHP 8.4 syntax support issue.

Having said that, property hooks is the bane of my existence and will be a nightmare to add support for in PHPCS. The tokenizer support alone is going to take months of work, as it is not 1 syntax they have added, but over a dozen new syntaxes, all under one RFC...
Only after syntax support is available through the Tokenizer can we start fixing individual sniffs and I expect 60-70% of sniffs in the wider PHPCS field (including external standards) will need updates, or at the very least additional tests with property hooks.

I spoke up about this at the time (and about other idiocracies in property hooks, it's a massive footgun), but unfortunately to no avail.
If you want to read my full analysis of the problems with property hooks, have a read through here: https://externals.io/message/123048#123080

All in all, please be patient, I expect it will be quite a while before PHPCS will have full support for property hooks.

Funding for this would help. Finding a way to clone me, would help even more.

@jrfnl
Copy link
Member

jrfnl commented Nov 26, 2024

Oh and this comment from me on the Internals mailinglist should also help illuminate why so many sniffs will need updates and how problematic property hooks are: https://externals.io/message/123048#123118

@jrfnl
Copy link
Member

jrfnl commented Nov 26, 2024

I've now opened the PHP 8.4 syntax overview ticket: #734

I think it would be a good idea to close this ticket in favour of the overview ticket.

@jnoordsij
Copy link
Author

Thanks a lot for your detailed explanation on the issue at hand, and also on all the time you spent on this earlier in the process trying to raise your concerns. I can only imagine how hard getting up-to-date with this amount of new syntax can be, so I fully understand that it might be a very lengthy process before this lands.

My main reason for raising this issue was mostly to have a place to track progress for future reference, both for me and others. I think #734 is a perfect overview to find that now, so I'll gladly close this in favor of that!

@jrfnl
Copy link
Member

jrfnl commented Nov 27, 2024

@jnoordsij Thank you for your understanding.

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