Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Readonly Class Side Effects Issue (PHP 8.2) #637

Closed
rm-IanLChapman opened this issue Mar 28, 2023 · 2 comments
Closed

Readonly Class Side Effects Issue (PHP 8.2) #637

rm-IanLChapman opened this issue Mar 28, 2023 · 2 comments

Comments

@rm-IanLChapman
Copy link

rm-IanLChapman commented Mar 28, 2023

Q A
Bug report? yes
Feature request? no
Library version 2.8.0

If you have a class like this:

readonly class FetchFiltersAction
 {
     public function __construct(
         private FilterOptionsRepository $filterOptionsRepository
     ) {
     }

     public function handle(FilterCollection $appliedFilters): FilterOptions
     {
         return $this->filterOptionsRepository->getFilterOptions($appliedFilters);
     }
 }

Then the following failure is shown:

  • [Side effects] A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 11 and the first side effect is on line 11.

(In this case line 11 references the first line in the code snippet above.)

I believe this might be a php 8.2 issue as readonly classes were only recently introduced.

Thanks :)

@Enz000
Copy link

Enz000 commented Apr 24, 2023

I have almost a similar error:

• [Style] Syntax Check:
  .Example.php:22: PHP syntax error: syntax error, unexpected token "readonly", expecting "abstract" or "final" or "class

my class:

final readonly class Example

@cmgmyr
Copy link
Collaborator

cmgmyr commented Sep 28, 2023

This has been merged. I'm going to leave the change untagged in master for a few days so others can ensure everything is working as intended

@cmgmyr cmgmyr closed this as completed Sep 28, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants