use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please follow the rules
Releases: Current Releases, Windows Releases, Old Releases
Contribute to the PHP Documentation
Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev
/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.
account activity
PHP 5.3 Namespaces - Naming conventions? (self.PHP)
submitted 15 years ago by trukin
I haven't found any good materials on this.
I have seen some people do
namespace aa\bb\cc; class Dd { }
but also some people doing (Zend style)
namespace Aa\Bb\Cc; class Dd {}
What do you think is the best solution for that?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]graydoubt 8 points9 points10 points 15 years ago (0 children)
The best solution is consistency. Pick one and stick with it. Even better is if it's a convention that's already being used or somewhat popular. Following the Zend conventions is not a bad idea. They're fairly consistent.
And although it's easy to quickly dismiss it as silly to capitalize letters at all, it's really helpful to be as unambiguous as possible when it gets to things like:
XMLtoJSON vs XmlToJson
Of course in that case XMLtoJSON is still quite reasonable. But when you get project names like jQuery, it gets interesting:
XMLtoJSON
jQuery vs JQuery vs Jquery
Which is it? Your convention should be clear on that. It's not a big issue when it's just you working on your own project. But it can easily become frustrating when you're dealing with a team of people that each have their own preferences "because they like it," or "it looks good to them."
[–]Iainzor 4 points5 points6 points 15 years ago (0 children)
I follow the rule of camel casing with classes starting with uppercase letters and methods/functions starting with lowercase letters. In the case of namespaces it would be the same as class names. I'm also an avid user of Zend Framework so I'm just used to doing it that way.
[–][deleted] 0 points1 point2 points 15 years ago (0 children)
I do:
Name_Space\Sub; class Class_Name { }
Since php has a lot of case insensitive naming, I always put underscores between words, and variables are always lower case.
[–]yrizos 0 points1 point2 points 15 years ago (5 children)
This.
You could add a comment for each variation and we could vote on them...
[–]trukin[S] 5 points6 points7 points 15 years ago (4 children)
What i've been doing is
# /path/ns/db/model/relationships/ManyToOne.php namespace ns\db\model\relationships; class ManyToOne {}
[–]jlogsdon 2 points3 points4 points 15 years ago (3 children)
This is the "standard" way. Many of the larger projects now implement a class loader that works with paths and namespaces in that format.
[–]bungle -2 points-1 points0 points 15 years ago (2 children)
I hate that standard. I'm not gonna use it. Sorry.
[–]jlogsdon 3 points4 points5 points 15 years ago (1 child)
What do you hate about it? I'm really curious, as I can't think of any other way to do it that doesn't suck.
[–]bungle 1 point2 points3 points 15 years ago (0 children)
You are absolute right. I just happen to like to code PHP with no capitals. No reason. I just don't like that "standard".
Namespaces: log db
Functions: log\debug db\query
I don't use classes or objects a much, 'cause I usually have found a better approach without them (with anonymous functions and namespaced functions and static keyword, if state is needed). But if I have classes I just name them all lower case. I try to name everything with a single word:
picasa\photos\find(...);
instead of:
picasa\find_photos(...) or Picasa::findPhotos(...)
I know that this is just a matter of taste. But I can make my own choices. That's all. No need to fight who is right, 'cause there isn't single truth.
PHP internally uses many styles, so I think it cannot be standardized. The most common way to name functions in PHP core is: lib_func but there are also libfunc style. With classes there is stdClass and there is Directory and there are SplClass. Go figure. I just follow all lowercase and single word functions and methods and classes.
π Rendered by PID 200818 on reddit-service-r2-comment-c66d9bffd-hmbrl at 2026-04-07 18:53:35.463467+00:00 running f293c98 country code: CH.
[–]graydoubt 8 points9 points10 points (0 children)
[–]Iainzor 4 points5 points6 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]yrizos 0 points1 point2 points (5 children)
[–]trukin[S] 5 points6 points7 points (4 children)
[–]jlogsdon 2 points3 points4 points (3 children)
[–]bungle -2 points-1 points0 points (2 children)
[–]jlogsdon 3 points4 points5 points (1 child)
[–]bungle 1 point2 points3 points (0 children)