Skip to content

Change visibility of handler classes to protected #1934

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

Closed
wants to merge 1 commit into from

Conversation

PillFall
Copy link

@PillFall PillFall commented Jan 13, 2025

Some properties and methods of the handler classes are set to private and some others to protected.

I change the visibility of all of them to protected. I believe this is a better practice, as it allows us to extend the handler.

If there are any security concerns of why this is the way it is, please do let me know.

Example

The MongoDBHandler stores the configuration private as shown:

private \MongoDB\Collection $collection;
private Client|Manager $manager;
private string|null $namespace = null;

But the DynamoDBHandler stores the configuration protected as shown:

protected DynamoDbClient $client;
protected string $table;
protected Marshaler $marshaler;

With how is the code right now, I can extend the DynamoDbHandler to add querying functionality, all without having to create a new configuration object (aka Aws\DynamoDb\DynamoDbClient).

But with MongoDBHandler, I have to redo the argument parsing in its construct function to include this functionality, creating also two copies of the same exact object in memory (aka MongoDB\Driver\Manager or \MongoDB\Collection).

@Seldaek
Copy link
Owner

Seldaek commented Mar 16, 2025

Thanks for the PR, however I do not think this is a good change as it makes refactoring much harder as the API surface becomes much larger.

We do accept PRs to open up properties/methods to be overridden/extended whenever someone has a valid use case though.

@Seldaek Seldaek closed this Mar 16, 2025
@PillFall
Copy link
Author

I do not think this is a good change as it makes refactoring much harder as the API surface becomes much larger.

@Seldaek can you explain this for me?

I don't get why this change will make refactoring harder, this PR will only change a private w/o extension to a private w/ extension.

The same properties and methods will be available in a similar fashion, but allowing users to further extend the API, there are zero noticeable changes for the user.

Also, this seems like a wanted feature and a main concern for users as this is a blocker for many projects.

See for example #1866, #1875, #1912, and so many others.

@Seldaek
Copy link
Owner

Seldaek commented Mar 18, 2025

Right now we get PRs to mark stuff protected when there's a use case for it. So we can discuss use cases, prevent some people from making mistakes, learn how people use it, etc.

If we mark it all protected, no method or property can be changed/refactored anymore without the chance of BC break. In terms of public API surface everything protected is part of the public API, and potentially used by someone somewhere.

I hope this helps clarify my view

@stof
Copy link
Contributor

stof commented Mar 18, 2025

@PillFall protected properties are covered by the backward compatibility requirements of semver (and properties are harder to handle than methods regarding compatibility layers when property hooks are not an option). Protected properties are closer to public ones than to private ones in term of impact on maintenance.

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

Successfully merging this pull request may close these issues.

3 participants