Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Clarify Lazy Services usage withfinal &readonly classes#21065

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
kiler129 wants to merge1 commit intosymfony:7.3
base:7.3
Choose a base branch
Loading
fromkiler129:patch-4

Conversation

kiler129
Copy link
Contributor

@kiler129kiler129 commentedJun 7, 2025
edited
Loading

Since Symfony 7.3 lazy services supportfinal andreadonly objects:

% grep TaskGroups src/UseCase/CreateUser.php final class TaskGroups extends YamlConfig% bin/console debug:container 'App\UseCase\CreateUser' 2>/dev/null | grep Lazy  Lazy             yes

This works sincePHP 8.4 allows for native lazy ghosts that don't need to extend the class:

finalreadonlyclass TestObject {publicfunction__construct(publicint$number) {echo"Constructor called\n";    }publicfunctiongetLucky():void {echo"Your lucky number:$this->number\n";    }}$lazy =newReflectionClass(TestObject::class)->newLazyGhost(function (TestObject$object) {$object->__construct(\random_int(0,100));});echo"Object created\n";$lazy->getLucky();

The support for this feature was introduced insymfony/symfony@ed695a6 (preciselyhere). However, documentation still points users to use Interface Proxifying, regardless of the frameworks or PHP version.

@@ -23,8 +23,8 @@ until you interact with the proxy in some way.

..warning::

Lazy services do not support `final`_ or ``readonly`` classes, but you can use
`Interface Proxifying`_ to work around this limitation.
Lazy services support for `final`_ or ``readonly`` classes was introduced in Symfony 7.3, and
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a warning anymore, make let's move this to a versionadded 7.3 directive?

@OskarStarkOskarStark changed the titleClarify Lazy Services usage with final & readonly classesClarify Lazy Services usage withfinal &readonly classesJun 19, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@OskarStarkOskarStarkOskarStark left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@kiler129@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp