elepil
asked on
Simple question about PHP variable-naming conventions
Having come from Java, the common naming convention developers use is the camelback notation, e.g. firstName, companyName, etc.
I'm going through a PHP book right now, and I notice that the author uses all lower case, multiple words being delineated by an underscore, e.g. first_name, company_name, etc.
I'm actually transitioning from Java to PHP, and I'm just curious. What is the MOST common variable naming convention PHP developers use, if there is one?
Only people who are working as PHP developers should respond, please.
Thanks.
I'm going through a PHP book right now, and I notice that the author uses all lower case, multiple words being delineated by an underscore, e.g. first_name, company_name, etc.
I'm actually transitioning from Java to PHP, and I'm just curious. What is the MOST common variable naming convention PHP developers use, if there is one?
Only people who are working as PHP developers should respond, please.
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yodercm, you're lucky you've never encountered a hard-nosed employer as I have. I will still wait for a few more feedback like yours before I assign points. Thanks for responding.
There is no mandated process, if you have a boss that says he wants it one way I'll show you another that wants it another way. (And that's when they know whats going on to start with)
If you are looking for a best practise that you should adopt then lowercase letters and nothing else, no underscores, no numbers, no capitals.
If you are looking for a best practise that you should adopt then lowercase letters and nothing else, no underscores, no numbers, no capitals.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Personally don't like camelCase but that's probably just because of my eyesight!
ASKER
Chris. Yes, I am aware that each company will have their own coding conventions. It is my objective to get a "feel" of what PHP development companies go by. From the responses I'm getting so far, there doesn't seem to be a very stringent standard, which is good.
I personally preferred variants of Hungarian notation where each variable is prefixed by the type (e.g. sName, iAge, fSalary, bNewUser, etc.) as one can tell the data type in one glance, but I've encountered a Java employer who insisted I use camelback.
I personally preferred variants of Hungarian notation where each variable is prefixed by the type (e.g. sName, iAge, fSalary, bNewUser, etc.) as one can tell the data type in one glance, but I've encountered a Java employer who insisted I use camelback.
ASKER
Cathal,
camelback notation is okay, but I prefer Hungarian (e.g. sName, iAge, fSalary, bCorrect, etc.)
What surprised me is that some of the respondents wanted lower case with no underscore. If I were to go all lower case, I would be using underscore a lot because 'percent_after_expiration' is, to me, easier to read than 'percentafterexpiration'.
camelback notation is okay, but I prefer Hungarian (e.g. sName, iAge, fSalary, bCorrect, etc.)
What surprised me is that some of the respondents wanted lower case with no underscore. If I were to go all lower case, I would be using underscore a lot because 'percent_after_expiration'
Things like 'percentafterexpiration' I would be using underscores, for vars like firstname I wouldn't be so bothered as it is still quite easy to read.
Haven't seen the 'Hungarian' version in years, I don't think most developers use it anymore, vars can be anything in php, you do not need to declare the vars type, a var can be a number and a string at the same time.
Haven't seen the 'Hungarian' version in years, I don't think most developers use it anymore, vars can be anything in php, you do not need to declare the vars type, a var can be a number and a string at the same time.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have always worked as a 'contractor' and not an 'employee' when I've doing PHP. The only coding I've done as an employee was using assembly language and Borland C and my employer had no idea what I was doing. So there has never been anyone to tell me what 'naming standard' to use. Thanks for the points.
ASKER
Dave Baldwin,
Borland C? Haha! Really? That platform died ages ago, did it not?
Anyway, it's good to hear that name again, brings back memories.
Borland C? Haha! Really? That platform died ages ago, did it not?
Anyway, it's good to hear that name again, brings back memories.
I think that Delphi is the current version of that but I was talking about 1995 at the latest.
ASKER
As a Java developer, I've worked in places where camelback was stringently mandated, and any deviation (e.g. Hungarian notation or php-style-lower-case) was frowned upon and would get you a scolding.
Can anyone tell me what their employers prefer/require them to use as far as variable-naming?