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

Eradicate internal usages of new $class #6635

Open
4 tasks
dktapps opened this issue Feb 17, 2025 · 0 comments
Open
4 tasks

Eradicate internal usages of new $class #6635

dktapps opened this issue Feb 17, 2025 · 0 comments
Labels
BC break Breaks API compatibility Category: API Related to the plugin API Type: Enhancement Contributes features or other improvements to PocketMine-MP

Comments

@dktapps
Copy link
Member

dktapps commented Feb 17, 2025

Problem description

Dynamic new is an anti-feature. It makes it difficult to do static analysis, usage searches, and also puts implicit requirements on constructors to follow a particular signature.

new $class is basically reflection and comes with all of the problems of using reflection. It needs to go away.

The following things still use dynamic new and need to be changed:

  • TileFactory
  • Block->writeStateToWorld() (to create new tiles)
  • World generators (this might be a bit complicated to address due to threading)
  • PlayerCreationEvent and general player construction

Proposed solution

Closures should be used instead. We did this with EntityFactory and with WorldProviderManager. It's a lot more flexible, fully statically analysable, allows extra parameters to be provided by the callback, and also allows the callback to do extra logic if need be.

Alternative solutions or workarounds

No response

Related issues

#6418 uses this anti-feature in new code
#3473 also affects PlayerCreationEvent, though not clear if getting rid of it is yet feasible
#6556 affects generators

@dktapps dktapps added BC break Breaks API compatibility Category: API Related to the plugin API Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Feb 17, 2025
@dktapps dktapps moved this to Todo in Breaking changes Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BC break Breaks API compatibility Category: API Related to the plugin API Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
Status: Todo
Development

No branches or pull requests

1 participant