MyBB Community Forums

Full Version: Namespaces
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Please use PHP namespaces in the includes files. Namespaces were introduced in PHP 5.3 (which was released in 2009). Namespaces would make it so much easier to integrate with other products. One of my biggest challenges in getting products to work together on my site is that they all have functions and variables with the same names (but different functionality) in the main namespace.
I'm sure namespaces will be used in 2.0 as it will use a framework and all the frameworks I know of use namespaces, at the moment, so it would be ridiculous that 2.0 won't utilize namespaces.
Includes files? There is only one relevant include in any modern PHP project.

require 'vendor/autoload.php';

If you're using autoloading and Composer that's all you need.

And if you're using Composer then you probably search for good packages on Packagist. Good packages follow PSR-0 or PSR-4, which require that you use namespacing. Frameworks too follow PSR standards.

tl;dr: Namespacing will definitely be used, regardless if we use a framework for 2.0.
(2014-04-25, 06:40 PM)Fábio Maia Wrote: [ -> ]Includes files? There is only one relevant include in any modern PHP project.

Fábio, I meant files (such as inc/functions.php) which are not directly accessed by the user.
I know what you meant. The question was rhetorical. Toungue

My point is these days you don't have a bunch of files such as inc/functions.php that you include directly, like you see in MyBB 1.x. No, you namespace everything, setup autoloading and then you can use whatever everywhere in your code.

In other words, you don't even think about namespacing because that's already implied if you're using autoloading.
Well,

if we will be using namespaces, then i think that many classes will have to be re-written Big Grin
Since, I see that various classes use the old contructor methods "Same name as Class" And namespaces will fail there.
That doesn't matter seeing as 2.0 will be a full rewrite anyway...