Hacker News new | ask | show | jobs
by lastkarrde 5544 days ago
Does anyone know why Fuel uses a mixture of Zend_Style class naming and namespaces? For example controllers are prefixed by Controller_ and are in the root namespace while tasks are put in the namespace Fuel\Task with no class prefix.

  class Controller_Foo{}

  namespace Fuel\Task;
  class Foo{}
It seems confusing.
4 comments

Fuel does not namespace everything as there is no need.

There are 4 main namespaces.

Fuel\Core Fuel\App Fuel\Tasks Fuel\Migrations

Then packages have their own namespace too.

These help code that could potentially have the same name exists and allows for easy extending of core classes.

Class Foo extends Fuel\Core\Foo.

Thanks to a cascading file system very similar to Kohamas this is all very simPlenand very quick.

The Zend_Style_Class equates to classes/Zend/style/class.php and could exist in core or app, or packages, etc.

I was unable to find this in the Fuel guide but I think Fuel uses a cascading file-system similar to that of Kohana:

http://kohanaframework.org/3.0/guide/kohana/files

Seems pretty lazy... it would be trivial to change the autoloader to check a Controller namespace/directory.
It has nothing to do with laziness. It allows you to override any part of the system without actually changing any of the core framework or module files.
I can't comment specifically on the Fuel framework, but it's probably going to take years (if ever) for "the right" way to use namespaces to emerge among the PHP communities. There's been a decade plus of ingrained name-spacing by convention that PHP developers will need to shed
There is already a standard.

http://groups.google.com/group/php-standards/web/psr-0-final...

Voted on back in 2009 by members of Solar, Cake, Doctrine, Zend, Symfony, Typo3, PHP Core, Yahoo! and others.

We actually keep pretty close to that, but have two implementational differences: 1. Namespaces are linked to a specific directory instead of just translated to a path 2. Our paths are fully lowercase

And I stand by those. The first allows for more flexibility when it comes to code organization and the second makes mistakes in classloading a lot less common. You can disagree with these but we have documented them clearly. Also it's quite easy to add another autoloader, ours won't even do a filesystem check when trying to load from an unknown namespace so it should add hardly any overhead to attach a Zend (or anything) compatible loader.

Doctrine2 and Lithium took the lead and went 100% namespaces. Other projects such as Symfony2 and Solar2 have followed suit.
It's in the PHP style guide? Maybe?
Nope.

Previous to PHP5.3 (when namespaces were introduced) most frameworks followed the Zend_Style_Of_Naming (That class would be located in Zend/Style/Of/Naming.php).

All new frameworks that support PHP5.3+ (with the exception of Fuel, it seems) have done away with Zend_Style_Naming and follow direct namespace <-> file mapping.

Seriously just curious, what are 'all new frameworks that support PHP5.3+' that are complying to that? And even with namespaces, I guess there are still a couple of ways on how to do this in the file system and handle autoloading. What's the 'standard' then?
I mentioned this in another comment.

http://groups.google.com/group/php-standards/web/psr-0-final...

Was 'ratified' by some of the bigger framework developers out there a while ago.