Eradicate internal usages of new $class
#6635
Labels
BC break
Breaks API compatibility
Category: API
Related to the plugin API
Type: Enhancement
Contributes features or other improvements to PocketMine-MP
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)PlayerCreationEvent
and general player constructionProposed solution
Closures should be used instead. We did this with
EntityFactory
and withWorldProviderManager
. 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
The text was updated successfully, but these errors were encountered: