6 ms·
A Crash-Course in PHP Namespaces for WordPress Developers
- firefoxd 8y agoThe WordPress ecosystem is the one place we need this the most. Adding a plug-in to your wp instance is always a gamble because you know it's gonna break something else. Kudos to the author for helping solve a real problem.
- jstewartmobile 8y agoNamespaces are more like a mitigation than a solution. The problem is tight-coupling. Until that is addressed, plugins will always be little fail-bombs.
- debacle 8y agoIt depends on the plugin. Some of these methods are just helper functions for template rendering. Loose coupling isn't going to contribute a ton there, but not polluting the global namespace is important regardless of coupling.
- jstewartmobile 8y agoWrite enough code, and you will know that "just" is a famous last word. An actor model approach where one failure doesn't compromise the entire chain would help, but that is hard.
- acobster 8y agoThere's more than one big problem with WordPress, and namespacing is one of them. It's way too common, even in some of the most popular plugins, to just toss plugins into the global namespace and prefix them with $your_plugin_abbrev_. I've had textbook cases of namespace collision take down sites on routine plugin updates before. The core design of WordPress relies on global state, e.g. the $post global. I agree that that's a huge issue. Unfortunately, that will never be fixed, because it's so central to the design that "refactoring" the WP core not to use global state would break almost every plugin and every theme, and would be a fundamentally different system.
- debacle 8y agoThe fact that WordPress and other large projects still support PHP 5.* is one of the major things holding PHP back. Supporting PHP 5.* in 2018 is like supporting IE8 in 2018.
- smacktoward 8y agoIt's a classic chicken-and-egg problem. WordPress supports ancient versions of PHP because they want to be deployable on as many web hosts as possible, including ones that only provide ancient versions of PHP. And web hosts provide ancient versions of PHP because their customers (lots of which are WordPress users) don't demand they provide more recent ones. It would be a huge help to the overall PHP ecosystem if WordPress started required PHP 7, as this would cut the knot and give those slow-moving Web hosts a reason to upgrade. But requiring PHP 7 would be a much smaller help to WordPress itself, as there's nothing in PHP 7 that WP really needs to do what it does, and dropping PHP 5 support would mean creating a non-trivial number of people for whom WordPress no longer "just works." (As the article notes, PHP 5.2 users only account for around 4% of the overall PHP audience, but the overall PHP audience is huge and 4% of "huge" still equals "a lot.") So to a degree, asking WordPress to drop support for PHP 5 is asking them to take one for the team. It would be nice if they would, but I can understand why they wouldn't want to.
- Joeri 8y agoMoving to php7 would allow those web hosts to host more customers on the same machine, as php7 is faster with a lower memory footprint. Everyone would be better off, even the cheap web hosts.
- smacktoward 8y agoI don't disagree that PHP 7 is much better in this regard than 5 is, and most clueful hosts have picked up on this and made the move. The problem is that there are a lot of less-than-clueful web hosts out there. And if you're less than clueful, the economic rationale for the upgrade probably looks less compelling to you than the "if it ain't broke, don't fix it" rationale for staying with 5 does. (Not to mention that staying with 5 means you don't have to do anything, and less-than-cluefulness and laziness often hang out together.)
- jakeasmith 8y agoHi, Steve.
- chryton 8y agoHey Steve.
- esaym 8y agoHow is this news? Been doing this in perl since 1995.
- aussieguy123 8y agoLook at the drupal source code on github, its all namespaced. The over a decade old wordpress core codebase is still old procedural style PHP.