I sometimes see in code commenting for PHP classes a category and package declared. What are they for? What’s the difference?
I would guess a package means all classes in it need one another to function whereas a category is just a way of breaking down large numbers of classes into groups.
If that is correct do you normally have categories and packages in their own folder—or is there some kind of naming convention?
I dont think there are any practical differences, at least not in PHP. Theoretically though, a package is a collection of classes in the same folder/directory, and a category is a collection of packages in the same parent/outer folder/directory. The concept is much more useful in Java, in which package is actually part of its language structure/syntax. PHPdoc is based on JavaDoc while the significant difference in PHP and Java’s functionality makes it somewhat confusing.
And nope, there is no need to have categories and packages in their own folder, its a matter of choice. In PHP you can use this concept called Namespace, which can organize folders much better, it also makes class autoloading much simpler.
Yes thats how it works in theory, but again PHPdoc’s category and package only serve as class organization system, its a matter of choice whether to follow this pattern.
It does not seem to me that PHP has this @inject annotation yet like Java does, but you can always use explicit comments to make it clear that your class needs dependency injection from another class.
No worries, I am glad to help. Its good to know there are this many OO programmers on this forum.
umm in PHP I doubt thats the way it works. If you are using namespace, your class’ fully qualified name will be something like Framework\Category\Package\Subpackage1\Subpackage2\…\ClassName. In this way you can easily organize your classes and create a generic autoloader that replaces the namespace operator “\\” with directory operator “/” to load your classes from the appropriate folders.
I see, yeah you definitely can do that, like I said its a matter of choice. I prefer using namespace though since it makes autoloading much easier and faster,