Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The consensus seems to be that one should follow the convention of the platform they're developing for. See:

Underscore or camelcase?

Naming conventions: camelCase versus underscore_case?

However, PHP doesn't seem to strictly follow any convention internally (no surprises there), even for methods and functions (e.g. mysqli::set_local_infile_default, PDOStatement::debugDumpParams); however, underscores seem to be dominant in function names.

However, what I couldn't find was this: what's the dominant naming convention for variables in PHP?

share|improve this question

closed as primarily opinion-based by ThinkingMedia, MichaelT, Corbin March, GlenH7, Bart van Ingen Schenau Aug 17 '13 at 11:16

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

Pick one and stick with it. It doesn't matter which one you'll pick, as long as you stick with it. Same with tabs vs spaces. – Yannis Apr 28 '13 at 9:54
I strongly agree with the opinion prevalent in the linked discussions: one should follow the convention. That's why I've limited the scope of the question to PHP. However, I'm starting to wonder whether there is a dominant naming convention in PHP. – sbichenko Apr 28 '13 at 9:55
There's not, naming conventions is yet another of those little inconsistencies that make PHP so wonderful to work with. PSR is the one effort that I think is worth following, but... it's completely up to you. Related questions: Are there standard style guides for PHP? & Why Bootstrap 3 changes camelCase to dashes - is it more readable?. – Yannis Apr 28 '13 at 9:58
This question might help you:… – Jason Apr 29 '13 at 16:21
The 1st link is dead but here is the archive:… – Dmitri Zaitsev Jul 8 '15 at 4:27
up vote 23 down vote accepted

There is no definitive naming convention in PHP, and they differ by framework:

So: Use whatever your framework uses or create your own naming convention.

At least for function names and class methods, there is a one thing to consider, but some frameworks discard it: PHP is case insensitive in that case, so aTonalFunction() and atonalFunction() are both calls to the same function.

share|improve this answer
Nothing against your methond naming argument, but that is absolutely not the convention. All modern frameworks and libraries like Zend Framework 2, Doctrine 2 and Symfony 2 use camelCase for method names. – Rudolph Gottesheim Aug 14 '13 at 14:50
@RudolphGottesheim Good point. I have edited the answer accordingly. – Residuum Aug 16 '13 at 22:04
Interesting. I came here because I found the coding convention of wordpress to be ungainly. Now I see at least they meant it to be ungainly – Kirby May 14 '15 at 4:06

As coding for more than ten years with PHP, I can see a change from underscore to camelCase. Especially the bigger frameworks like Zend and Symfony build up on camelCase also when they don't prohibit underscore, but all the core function is camelCase.

You can see a lot of underscore solutions in older systems, like the old Typo3 branch (Typo3 Neo changed to camelCase, too).

But there is definitely no strict rule, which is used by everyone, that's just what I can see over the past few years.

share|improve this answer

This is depends on the programmers/developers as well as on which framework or open source he or she is working on. For eg, in Yii framework it is advisable to use camel case, where as in the Codeigniter framework people mostly follow variable names with underscores. But one thing is for sure that what ever framework you use the variable name must be user understandable and must be identified with it's usage.

share|improve this answer

Personally, this can go either way. Some programmers prefer the CamelCase way of writing, others prefer underscore.. So asking a question like this posses it's irrelevance as each programmer will have their own different opinion.. Personally, I have the habit of doing both depending on the situation..

Situation one:

You have joined a programming team and have joined an on-going project, you notice that an example variable is set out:

$TheString = "This is a camelcase example";

But you have a preferred style of:

$The_String = "This is not a camelcase example"; 

in a situation like this, it would be best to keep to camelcase.

Situation two:

You wish to start a project solo.

In this sort of case.. It just goes down to what you feel comfortable with, bare in mind bad practices in terms of:

$TheString = "This is a sample String"; 
$The_String = "This is another sample string within the same project"; 

This can easily cause unexpected output.. Just bare that in mind.

share|improve this answer
FYI, what you are referring to is PascalCase - camelCase starts with a lower case letter. – John White Dec 16 '15 at 0:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.