Compared to Kohana 3.1

As I pointed out on the topic linked below, we’re having a “Yii vs Kohana” discussion next week so I’ll need Kohana (strictly Kohana 3) developers with Yii experience to point out all the bottlenecks / advantages of both frameworks.

Please skip the flaming part, I’m here to get your opinions, not to listen anyone bitching about me “being subjective”. Facts only. - Kohana vs. Yii


I should say I am not familiar with Kohana and the only php framework I user for real projects is Yii, but I am always interested in learning other frameworks / libraries to get some new good ideas or examples of solutions for some complex problems. For example, I used some Zend components, some ideas form Ruby on Rails and Fat-Free micro-framework.

Before starting with Yii I developed desktop applications in C++. I’am writing this because I want to say I seen many code of many software products in different programming languages and I can say that Yii is definitely one of the most good written, well documented and true OOP code I ever seen.

And yes, the code conventions in the Yii sources are not usual. I can not say my eyes were bleeding (as say some people on the Kohana forum), but it was difficult to understand from the first sight - just because on unusual look. But this is just a habit and no one can say that the code is bad just because if formatted not in the way someone expected.

After week or two working with Yii I just realized that the code style does not disturbs me any more and now I even like it (and even more have a thoughts to use it in my projects).

This is because Yii code conventions have a practical background:

  • tabs and not spaces (this is also used in the Kohana, so possible not a problem for you): less typing and smaller file size

  • no extra spaces: more compact code and as the result more code fits on the screen while reading / writing)

  • CamelCase - this is what I just like because always used it

  • and so on

What I still do not like (also because of practical reason) is no brackets for single line statements, because it complicates debugging:

if ($this->checkSomething() && $this->checkSomethingElse())


In that case when I step line by line I can not step over $this->checkSomething() and $this->checkSomethingElse() and should go inside to finally get into $this->doSomething().

And now some comments for you points at the Kohana forum:

> Strict development - Kohana being really strict about it’s additions / conventions

Yii uses "convention over configuration" approach, but also gives you a chance to change defaults if you want or need this.

In most cases you just can follow default conventions, without need for configuring everything.

> Unit tests - Kohana being completely unit tested

Yii also is well tested. I can not say anything about percent of code coverage, but you can look at existing tests here -

> Userguide - ability to have the whole framework and application (with API) documented ‘automatically’

Yii has custom command (can be found in svn - to generate framework documentation.

It is not complex to customize this command to generate documentation for your project or for your project + framework code. You just need to follow PHP Documenter conventions.

> Actual OOP

As I said above, I think that Yii is a great example of true OOP project.

> No pattern abuse / misuse (e.g. having the Event / Behavior patterns in Yii opposed to Kohana where nothing ‘hacky’ like that is used)

This is not right to say about abuse or misuse of patterns just because Kohana does not use Event and Behavior.

Both of these patterns and its implementation in the Yii CComponent gives you really great flexibility in extending objects without inheritance or even "on-the-fly".

And also you do not have to use them, its just an option (but very good option and it worth to learn and use it).

> No convention abuse - Yii has quite a few convention flaws, e.g. using eval() "natively"

Can not understand what definitely you mean here. Yii does not use "eval" to do some important things, just in a few places to allow more flexible configuration (like business rules in the RBAC configuration or specifying php expression for cache dependencies and also in some widgets).

> Actual hierarchy - Kohana has class naming / file system placement conventions strictly defined opposed to Yii where … classes can be all over the place

Yii has defined convention on where to place classes and how to name them. You can use some additional folders if you need this and do explicit import, but I think you can do the same in Kohana too.

Also code generation features allows you build a project skeleton and generate controllers / models / views - all in appropriate places and named regarding to convention.

> Modularity - the ease of adding modules and overriding / extending framework’s classes inside of them

Can say the same about Yii.

> HMVC - being "what PHP always missed", having a useful pattern like this and respecting the RFC 2616

I read some docs about HMVC in Kohana and it seems that it is different from classic MVC because of "rerouting" feature - when you execute other controller/action from the current action, right?

In Yii you can do the same using forward() controller method, like this:

public function actionComplexPage() {

    if (some_condition) {




> Know what the framework is doing by reading it’s clean, well documented code (opposed to Yii where the coding convention itself isn’t readable, not to mention having the whole method commented before it’s definition only)

Again I can say the same about Yii (except for unusual code style which is a problem only at the beginning).

> You want to program and not write arrays

What do you mean?

In Yii you always can extend base class instead of configuring it. And in some cases it is even easier, but this is always up to you - extend or configure.

In the conclusion: I think every popular framework or library with large number of users (like Yii or Kohana or Symfony) does its framework’s job well. Otherwise how it become popular? I never seen an advertisement of Yii or Kohana on TV )). Every framework can have some unique and good features, but talking about “Framework1 VS Framwork2” is always leads to some users holy war.

So if you familiar with Kohana then now you have a great opportunity to learn Yii and know the best sides of each, so you will be able to make both of them better by contributing ideas and feature requests or porting some components.

The bleeding is a result of using Yii conventions after something as nicely written as Kohana (no offense) :)

And what would happen if you were put on a project with developers working with actual php conventions? ( )

Nope, the actual result is impossibly unreadable code. Look at Kohana’s … controller for example and compare it to Yii’s.

Yes, people coming from Java / C / C++ / whatever usually do like camel case, though … is it really how php was to be written?

That’s not even closely same as accessing “/guide” or “/guide/api” (to access your whole application API which is always fresh). And yeah, PHPDoc can be used on any project anyways, it’s like if I were braging with Zend Framework’s features just because it can be used as a module in Kohana.

Observer pattern surely isn’t natural to use in PHP. Have you ever actually looked at how bloated Yii’s source code is because of it? When PHP natively gets to … for example, allow __call() to trigger on each method call (eexisting or non-existing on), Observer will make sense (never?). Kohana used to have it in version 2 but for these particular reasons it’s been deprecated and removed.

eval() should never have a place in any framework, everything a framework can do with it is hacky and unefficient. Devs should have waited until 5.3 with this one, not misuse the language.

Yeah, "defined" being a funny word. Yii has some convention, being unusable (unreadable?) without a IDE. How else is one supposed to know that "new Something" is a model?

Scaffolding is for lazy developers (I won’t comment Widgets which seem to actually be for ex Joomla users)

No, you can’t. Kohana allows every module to have it’s own framework extensions, while respecting the same file system structure as application/system folders. Every module is a mini-app for itself, more like ruby gem than what yii does.

Man you’re wrong on this one. Forwarding is nowhere near a HMVC request. Imagine this:

public function action_index()


	// Doesn't make an additional http request (HMVC magic)

	$json = Request::factory('api/posts')




	// Pass the response to view

	$this->template->content = View::factory('index', array(

		'json'	=>	$json,




 * More info at


You seem to actually really like Yii’s “conventions”. I won’t comment having 5 different render() methods inside of a controller, the whole mess with observer in … pretty much every method, code comments placement, etc.

Does anyone really think widgets feel “natural”? Writting infinite arrays just to later figure out you can’t change anything (in a table, for example) without hacking the widget’s class? Meaning, actually hacking, making it’s codebase even funnier than it’s initiation params? Though, every framework leaves extending as an option, even … Cake does that :P

Please notice that I concur on the rest of your comments, especially on the opinion that we should contribute to both frameworks and make them better.

I don’t hate Yii, I just think a lot of the things it’s trying (too hard) to do should have waited until php 5.3 / be left for Joomla “developers”. And hopefully conventions will be radically changed in 2.0.

And one last thing; back-end frameworks shouldn’t have any JavaScript glue. If you’re following Rails already, please follow them on that one as well.

I find it funny that you register just to do that: flame.

What’s the point? :lol:

Would you now please go back to your Kohana community and leave the Yii community in peace?

All your reasons why Kohana is so much better than Yii is exactly the reasons why I chose Yii over Kohana. ;)

What’s your favorite color, by the way?

I really think the world is better in colors than in black and white, don’t you think?

Oh, and I really do like widgets in Yii - an excellent way of reusing oft used chunks of logic/presentation.

But I respect other opinions, other frameworks - and so should you.

Instead, I hate brackets for single line statements. Brackets exist in order to group multiple lines: no multiple lines, no brackets, they aren’t needed, they shouldn’t be there. Indentation improves readability, not brackets.

I usually put brackets there, because it clarifies the scope - and because I can easily add additional code later on.

It’s just a matter of preference - although a lot of projects follow that convention, maybe not PHP, but definitely C++.

I tend to follow the Zend coding conventions -> coding-standard.coding-style

I think the Yii developers are the right people to decide what coding conventions they use. IMO.

“Nicely” is not an objective opinion. However, I don’t use every Yii source convention for my webapps. It’s a framework, I use features exposed by the framework, I don’t care about its coding style. If you code C# applications, do you care about the .NET Framework coding style? Not really. Methods/functions/etc. naming is the only convention you can see.

I don’t see unreadable code.

Probably it’s how PHP should have been written. Modern languages like Java, C# etc. use camel casing and it improves readability. This is one of the reasons why I chose Yii (and PRADO before): it’s fresh air for an old-conception language like PHP.

About guides… Kohana documentation is plain ridiculous compared to the Yii guide

Also, Yii class reference is better organized

That __call() magic is very nice but it’s not less hacky than what you called hacky.

Scaffolding is for developers who spend time doing something useful, manual CRUD is for monkeys. Also, I think you didn’t understand what Yii widgets are.

And what about permissions management? RBAC? Active Record? Caching (page caching, segment caching etc.)? Web service features (SOAP etc.)? Performance? I think that Kohana is nice… but it’s a toy.

If you add code, you also add brackets ;)

Alright - I was about to post a comment that one reason I like the Yii community is that it’s wonderfully free from evangelists and bashers, but Ekerazha proved me wrong.


Like I said: I tend to follow the Zend coding conventions wherever I can.

They probably have good reasons for having it.


I understand your points, but still not changed my opinion regaring all initial questions, so do not see a sense to comment your answers, because it would be repeating the same using other words.

The only thing I’d like to discuss is HMVC request - Yii’s forward() also does not make any HTTP request and just runs another controller/action based on given route, so the idea is the same. It maybe not so convenient as in Kohana, because forward() will not return rendered content, but you can easily get it using php ob_xxx functions and also may need to manipulate with superglobals to pass parameters to the invoked controller. But both getting rendered content and passing parameters can be easily wrapped to something more OOP-like.

Am I missing something else regarding the HMVC?

Also it is interesting whether this concept is something widely used in Kohana projects or just an option for some complex cases?


As I written above, the reason why I use brackets for single line statements is for more convenient debugging - otherwise I should step into methods invoked inside condition to be able step into the doSomething() method. When there is no brackets then whole statment executed in one step (I use Netbeans + xdebug, maybe there are some other options).

I thought i just drop my two cents here having experience with KO3 and CI, so here it goes:

It is pretty hard to put Yii and Kohana in the same “basket” because the only thing being the same between them is the fact they are frameworks, but that’s all, everything else is treated in other way for each of them.

People who blame Yii(or everything pointing directly to yii) are just frustrated people not understanding what Yii means. It is also true that Yii requires more experience from a developer than other frameworks, but it also offers some amazing features and a high development speed(this is by far the best advantage YII offers).

I don’t know about you, but in the company where i work, we always have some strict deadlines and we cannot afford to go over them. Time is money, really.

I have nothing against Kohana, au contraire, i use it pretty often and i like it a lot because it is very lightweight. I also use Codeigniter for same reason, being lightweight(though is true, Kohana is taking CI place in my projects because, well… unfortunately CI is behind the times, but i am forced to stay with it because i have more than 30 active projects built in CI which needs upgrading and maintenance and further development) .

Yii makes the developer job easy enough, easier than Kohana can do it, or CI matter a fact, but this comes with a price, a higher memory usage and CPU usage for each request, therefore the environment where the app will be deployed needs to be more "special". But when APC/XCACHE comes in place, this is not a problem anymore, at least not so big.

I really think the learning curve is the decisive factor when choosing a framework. Lots of people say Yii is easy to learn, which is false, i had a very hard time understanding it and also took some time to realize what goes where and why (I am coming here having 2+ years of CI background, not counting the procedural programming years and still was pretty hard for me to get started with yii), but now i am getting the point and it makes sense to me(though i know, i have a long road before me till i will really understand this framework).

In my case, i don’t stick to ONE framework because for some projects makes more sense to use one than another, so before i start building the website i look at the requirements and at the time given till completition and make my choice between the three of them (Yii/CI/KO3)

Just as a side note, i have started a modular CMS several months ago (based on CI) which is very mature right now, but as much as i would like to rebuilt it under YII, i am still not decided if i want to do so because of the memory usage. I have in mind the issue of shared web hosting, where the servers are not very powerful(or if they are, they are very loaded anyway) and the memory/cpu limit will be always a problem. So in this case, i would rather continue with CI or rewrite it in KO3.

(P.S: i may be going too far with this memory/cpu usage thing, but i had the bad luck to face very ugly situations because of the after mentioned issues, so that’s the reason i am being this way.)

As you see, beside the learning curve, the deploying environment is another important factor to take into consideration.

In the end, it is important to choose the right tool for the right job.

Keep in mind, there’s no universal tool that will match every job you need to do (that’s why we have 50+ php frameworks and 100+ Open Source CMS systems)

Well said, Twisted. :)

Yii is difficult?

It really depends on where you’re coming from…

I started out using CakePHP, and it was relatively easy for me because I already knew object-oriented programming in C++ and a tiny bit of MVC (Qt Framework) - still I spent some time getting over that convention thing. :)

Yii is a lot easier to get into - comparatively.

It’s also a lot more lightweight than CakePHP and Symphony.

Quite a lot, actually.

I bet you can almost get the same speed as Kohana and Code Igniter if you are clever, and rewrite expensive AR operations into regular sql queries.

Closer to the metal usually requires a bit more work, but it’s also (usually) easier to understand because it’s not abstracted as much.

Still, Kemal has a problem:

His boss wants him to use Yii, and he wants to use Kohana.

I won’t discuss framework vs framework anymore, as everyone here noticed (and in my own opinion, to be honest), no arguments can “proove” to developers on both sides that the other one is better. Reasons of my initiative are ‘explained’ below (not saying that I’m explaining myself!);

The company is growing really fast and all kinds of PHP developers are coming into the team; even those without any framework experience. Now, the learning curve for Yii is extremely slow, even for someone who has a lot of experience with many PHP frameworks, causing missed deadlines, costing the company a lot of development time / money. The only developers that get to actually use Yii and deliver “in time” would be those who’ve been late with it during the last year of using it. Not to mention how hard it is for new developers (especially those new to framework) to get on a project which’s been worked on for past 9 months.

So, I don’t really have a problem. My company has a problem, and I’m personally here to find a development side of solution.

Not to advertise Kohana, but it does have more than 5 ACL / RBAC modules, prepacked Cache module (besides the fragment / page / request caching which is developers job to introduce into the application). Let’s say that implementing REST with Kohana is practically a joke, thanks to HMVC and Request / Response rewrite (RFC 2616).

Concerning ActiveRecord, Kohana has more than 4 modules for that purpose only, it’s up to you to choose (prepacked ORM, Sprig, Jelly, AutoModeler). I won’t suggest you try ORM, you’re obviously guessing and being far more subjective than “I am”.

Again, I’m not here to flame, I’m here to get your subjective and objective opinions (tnx @twisted1919).


well, for me it was pretty hard, i don’t know if you ever took a look into CI, but it is just something else than YII.

Kohana, being a fork of CI (well, it has it’s own road now) was easier for me to understand (example, i never posted a single thread on kohana forums because i never was in need for answers, i found the way by myself.

(i don’t know if it is just me, but kohana forum is very strange, pretty hard to follow for me)

But, the truth is, i am really happy that i choose to learn YII, i need to know as much as possible about as many things as possible.

Regarding the optimizations tips you were talking about, i agree with you 100%, those can be done, just that, right now i don’t feel i am an advanced YII user. Everything on it’s time :)

@Kemal Delalić

As i said, the learning curve is not the fastest one, but have you ever thought that as a personal goal, learning Yii would get you professional advantages ?

I am not sure how your company decides what to be used for what project, but i assume this is the role of the developers assigned for the project.

So leave aside the YII developers from your team(you know, they invested a lot of time in learning YII, would’t be nice to throw all that away, would it be ?) and maybe tell your project manager that you want to use your framework of choice in the project assigned to you, i am sure they can’t refuse this, makes no sense to do so.

When they accept, do an awesome job with your framework in a short time and impress them, then you’ll see what comes. There is now way for them to trust what you say about a framework unless they can see it in action.

Sadly, i have no other advices for you, but from my point of view, a company with people knowing to work with more than one framework(freedom of choice, right?), is a great company.

Btw, you are a lucky developer having to work only with frameworks :) (most of us, working on a daily basis with joomla/drupal/wordpress/OSC/Open Cart are not so lucky :) )

Blah blah blah talk about the subject and avoid personal attacks ;)

The mere purpose of a framework is to not reinvent the wheel, the fragment / page / request caching shouldn’t be “developers job”. Kohana is seriously lacking here. Also, you have to rely on third parties, amateur modules because it also lacks decent permissions and database management (not some minor feature). These are facts. And what about SOAP? And what about performances? Is there something like yiilite.php for Kohana?

As I said, there’s no point in discussing both frameworks with someone who hasn’t even tried both of them. Again, I’m not here to flame or h8, I’m here to get all kinds of opinions and you already gave yours’. Enjoy using Yii, I know I will :) (but not as much as using … whatever, you see? no point.)

Thank you for your opinion!

I agree. Unfortunately, this would exclude you from the discussion :)

Would it?

He is using Yii at his work - that’s the motivation behind this topic: convincing his company to move to Kohana.