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

Configuration: mutable dependencies shouldn't be cloned #579

Merged
merged 1 commit into from
Jul 25, 2023

Conversation

Slamdunk
Copy link
Member

No description provided.

@Slamdunk Slamdunk added the bug label Jul 25, 2023
@Slamdunk Slamdunk added this to the 9.0.0 milestone Jul 25, 2023
@Slamdunk Slamdunk self-assigned this Jul 25, 2023
@Slamdunk Slamdunk merged commit 3ce8459 into psr7-sessions:9.0.x Jul 25, 2023
@Slamdunk Slamdunk deleted the dont_clone_interface branch July 25, 2023 13:18
$new->jwtConfiguration = clone $jwtConfiguration;
$new->jwtConfiguration = $jwtConfiguration;
Copy link
Member

Choose a reason for hiding this comment

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

This was on purpose: the cloning is specifically done to NOT have the JwtConfig change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, and that's wrong: mutability is part of an API, if an object is designed to be mutable we cannot violate its design.

We can only enforce immutability on our own library, not the others.

Copy link
Member

Choose a reason for hiding this comment

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

Strong disagree: this is exactly why cloning is done here, to "detach" from the other system.

It was explicitly added here, on purpose.

Copy link
Member Author

@Slamdunk Slamdunk Jul 26, 2023

Choose a reason for hiding this comment

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

I'm not arguing the why: it has always been clear to me, and I agree with that.

I'm saying that even though we are capable of cloning external services, we shouldn't consider ourself allowed to.

A mutable dependency can contain all sort of interconnections with other services, and bad OOP practices.
We are type-hinting some interfaces, and it would be legit for me to feed a dependency that impements that interface and extends the \Doctrine\ORM\UnitOfWork: image the distaster if we clone such Kraken.

Copy link
Member

Choose a reason for hiding this comment

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

Right, but we are cloning a config object here, not a UnitOfWork: dereferencing and common sense, please 😛

Let's revert this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done 👍

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants