Opened 5 years ago
Closed 5 years ago
#48963 closed enhancement (duplicate)
Deprecate and replace globals in core with service container
Reported by: | taraschr | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
Global variables are "dark" legacy from PHP 4 but widely using in WordPress. Globals are dangerous and causing many problems - it is too easy accidentally rewrite or unset, their behavior can be very unpredictable. I think all problems are well known.
I suggest to add something like service container to WordPress core. It will not complicate understanding of WordPress core but will do more clearly and predictable in development process.
Globals can remain with that but deprecated and no longer recommended for use anymore.
Change History (2)
Note: See
TracTickets for help on using
tickets.
Welcome back to Trac, @taraschr.
While there is a recent trend in keeping WordPress core modern (with error handlers, PHP 5.6 as minimum PHP version, etc), WordPress still tries to be vastly compatible with millions of existing sites.
I suppose the first steps would be add support for composer packages, which would then allow to use a container like Pimple. It wouldn't make sense to allow containers/service locators for classes that are already instantiated and just scattered every where... i.e how things are right now.
I welcome you to join the Slack channel to have a conversation with core maintainers, specially
#core-php
on this.