Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

most used variable naming convention

Status
Not open for further replies.

Itshim

Programmer
Apr 6, 2004
277
US
I understand that this is a completely subjective question, but recently I have been creating PHP classes which I would like to distribute to the PHP community, and I was wondering what variable naming convention is most used (other than creating a name which describes the value)?

I don’t know where I picked it up, but I have been using:
Code:
$strName = ‘Name’;
$arrNumbers = array(1, 2, 3, 4);
$intCount = 42;

As I’m sure you can tell, the first three characters represent the variable type, and then the name starts with a capital letter. Looking through other published code, it seems no one else uses the prefix for type, and only lower case is used. I just want coders to be able to seamlessly incorporate my classes into their projects. I figure I can’t make everyone happy, but most would be nice.

Thanks for your opinions,
Itshim
 
When distributing classes I don't care so much about the inner workings, variable name conventions as for good documentation.
Any Java type documentation will give the reader the answers and saves you many three letter prefixes.
/**
* This is a sample class
* @author Itshim
* @version 1.0
* @var $name string A string value with the name of the object
* @var $counter integer The initial integer value
* @ return object
*//
That seems to me a good investment into re-usability of code. Interface and code documentation makes a real professional product. Run it through PHPDocumentor and the documentation will rock.
 
What you are using sounds like the hungarian notation. You put a prefix to the variable to describe it's type.
This convention is from Microsoft. A lot of people discourage this convention for many reasons, read about it here:

For php, I mostly just name variables to something meaningful. ALWAYS have them start with a lowercase letter and I usually use one letter variables for counters and temporary variables. PhpFreaks suggest a good naming convention in their tutorial:


Well like you said, it's very subjective but i wish you good luck with your project!
 
Thank you both for your suggestions.

DRJ478:
I am using Zend Studio 4 for coding, which has PHPDocumentor incorporated into it. I just spent a couple of days (learning curve) creating the documentation for one of my classes. I currently output a pdf file to be distributed with the classes. I did notice there is an XML PEAR doc, and an option for 'PEAR package repository parsing', but I have not looked into them yet.

sylve:
Funny you should mention Microsoft, a couple of years back I worked for a company which strictly used VB and ASP for coding, I'm sure I picked it up from them. (I was a tester)
Thank you for the links they were very helpful.

As for my original question; I was just wondering because I posted one class on a message board recently and everyone seemed to think the class would be useful, but asked if they could change the naming convention before using it in their projects.

Thanks again,
Itshim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top