Namespaces in Yii 2.0?

will Yii 2.0 use Namespaces?

http://www.php.net/manual/en/language.namespaces.rationale.php

that was an obvious question.

It was! :lol:

I can’t find it right now, but I am fairly certain that namespaces is one of the major things in Yii 2.

Also the reason why it won’t run on anything else than PHP 5.3 +

Namespaces are already supported since 1.1.5.

The main thing that its not just supported, but uses it.

Since Yii 2.0 will require PHP 5.3 + that’s not going to be a problem there.

All the PHP 5.3 goodness is not backwards compatible.

Like reflection, namespaces, …

Hence the major version.

What’s the big deal here? As long as you don’t have classes like “CController” in your other code (which i guess is not very likely, due to the “C” prefix) you won’t gain much.

I don’t see any benefit either.

Are you kidding?

Coming from C++, I am a bit surprised.

In the world of C++, a framework which pollutes the global namespace is a bad framework.

I am embracing namespaces in PHP.

And in Yii.

The problem is, that namespaces lift the requirements up to PHP 5.3 and thus would lock out a lot of users. To me that’s a much bigger issue than being able to have a framework class called “Controller” instead of “CController”. I never had any clashes with other classes and i don’t know of any other project that also uses the “C” prefix for their classes.

Still i wonder, what else would be the benefit of using namespaces? Better performance? I don’t think so. Easier code? Not really much, at least not in the application code.

So in my opinion Yii 2.0 might be too early to introduce namespaces. But i might miss some other big advantage (like maybe class loading - i admit i didn’t look closer to that yet).

What about developing or using code that doesn’t belong to Yii at all, and at some point it happens so, the next you find out that general programmer use conventional words like controller,view,model,test,index,main,all, in all parts of big program it should mean in context.

second idea is that would have more easily develop flow when you can have 2 namespaces one for debugging/development and other for production,productivity and speed.

generally using namespaces will help create bigger applications and use other code.

The prefix ‘C’ can be considered as a namespace for all Yii core classes (just like yii.* if we use namespace).

In general, it is the application code that needs namespace the most, if it wants to be organized well and avoid naming conflicts with its code in different modules or integrated 3rd party code.

Since Yii 2.0 will raise the basic requirements to 5.3+, it is certain that we will use namespace for the core classes. However, namespace is not the main driven force for us to rewrite Yii.

I disagree.

I embrace namespaces in PHP, but I don’t see it adding any value to Yii’s standard package of framework components.

Yii was already “namespaced” since it’s inception - which at the time meant using a convention, a class-name prefix. Yii chose a short class-name prefix “C”, but it still reduced the chances of namespace collisions enough to make your concerns pretty much irrelevant - I don’t think you’ve ever actually run into a situation where a Yii class collided with a third-party class?

The namespace feature in PHP is very “bread and butter” in the first-place - it’s really not much more than syntactic sugar, and as such, doesn’t really solve the problem any better or any worse than convention-based approaches, such as used by the Zend framework, PEAR and others. It doesn’t really bring any of the convenience or practical aspects found in other languages like C# or Java.

In my opinion, with existing support for namespaces in third-party libraries, or in your own codebases, Yii’s part of the job is done. If you want to use namespaces in your own applications and libraries, you’re good to go.

On another note, Yii relies on a number of third-party components, which do not use namespaces.

And finally, for framework components, which naturally get used a lot, I think there’s a convenience factor - “CJSON” is just easier to type (and easier on the eyes) than “Yii\web\helpers\JSON”. Yuck.

If it ain’t broken, don’t fix it :slight_smile:

On a related note, namespaces would be of great value for third-party modules and components, as they would largely eliminate the risk of collision. If a Yii-module was required (or at least strongly encouraged) to use a namespace, I think that would be a sensible convention.

As more and more frameworks (Doctrine2, Symfony, Zend) take to rewriting their core and adopt 5.3 namespaces, it only makes sense to adopt namespaces for Yii version 2+. With current support for namespaces in application code, i’m already writing in this way so I don’t feel the urgent need for the core framework to be namespaced.

Yii 2+ in my opinion is more about design patterns, ideas and improvements than namespaces alone.

EDIT:

Just to add, I think I would like to see a better coding standard in Yii 2. The source code is difficult to read in parts :slight_smile:

like where?

I think this is probably the most legible, and easily one of the most well-commented, codebases I’ve ever seen.

Before the old coding standard discussion starts again, please read here:

http://www.yiiframework.com/forum/index.php?/topic/3667-coding-standard

Things like implied true|false, non-bracketed statements on single lines, no spaces between operators etc. E.g.




//.. YiiBase:193

if(($n=func_num_args())>1)


//.. YiiBase:190

if(!class_exists($type,false))


//.. YiiBase:395-404

if(strpos($className,'\\')===false)

	include($className.'.php');

else  // class name with namespace in PHP 5.3

{

	$namespace=str_replace('\\','.',ltrim($className,'\\'));

	if(($path=self::getPathOfAlias($namespace))!==false)

		include($path.'.php');

	else

		return false;

}



Things like this (in my opinion) just make it harder to read and understand on first glance. Especially for people new to the Framework who want to understand the workings of the framework.

Yii Developers: I love this framework, so don’t take it as a negative criticism, just an observation on a personal preference.

I am a .NET developer and there r a lot of ideas.

one of them is using namespaces.

I can easily access my references via a simple code.

By the way in Visual Studio it supports namespaces by Intellisense Tools.

I agree to develop namespaces everywhere in Yii