atholon Posted May 15, 2008 Share Posted May 15, 2008 Hi all, I would like to know something about PHP and HTML naming conventions, perhaps JS if anyone knows. I would like to know how multi word variables should be named. I was reading o' reilly's php book and they stated you should name them something like my_var or similar. Is that the actual standard? What about functions or classes? Link to comment https://forums.phpfreaks.com/topic/105805-naming-conventions/ Share on other sites More sharing options...
Mr. Despair Posted May 15, 2008 Share Posted May 15, 2008 From what I see, it's usuallly my_var or myVar. Link to comment https://forums.phpfreaks.com/topic/105805-naming-conventions/#findComment-542260 Share on other sites More sharing options...
jt Posted May 15, 2008 Share Posted May 15, 2008 I prefer $oneTwoThree (lowercase first word, uppercase first letter of every following word) Link to comment https://forums.phpfreaks.com/topic/105805-naming-conventions/#findComment-542277 Share on other sites More sharing options...
atholon Posted May 15, 2008 Author Share Posted May 15, 2008 I know that in Java it is "myVar" for functions and variables and "MyClass" for classes. Link to comment https://forums.phpfreaks.com/topic/105805-naming-conventions/#findComment-542291 Share on other sites More sharing options...
soycharliente Posted May 15, 2008 Share Posted May 15, 2008 IMO, there is not a specific way to name your variables. No standard that you should or should not follow. Though in some languages, there are some rules that people have picked up. Look at the name variable. It's kind of obvious that it could vary. Sort of a double meaning. You can name it however you want. The one piece of advice that I could give to you, that I've given to many people while I was a TA in school, is that you should at the very least try to name them something so that if someone else read your code they would know what data it was holding. If you start programming and then decide to leave and come back, your variables might help you remember what you were trying to do. Doing something like: <?php $banana = 5; // insert 100 lines of code echo $banana; ?> You might forget what the heck $banana has in it. But something like: <?php $num = 5; // insert 100 lines of code echo $num; ?> You may remember that it actually holds a number when you finally get down to that code and can't see the line that defined it. Along the same lines as the other people, I usually follow the convention of $dataForTable with no underscores and a capital letter at the start of a new word. However, I think that $data_for_table is just as good an alternative. To me, it's six of one and half a dozen of the other. Obviously the first way uses less keystrokes, so if you're worried about how big your files are you might go with the first way. But unless you're using hundreds of variables over many lines, it's not going to make THAT much of a difference. Link to comment https://forums.phpfreaks.com/topic/105805-naming-conventions/#findComment-542354 Share on other sites More sharing options...
atholon Posted May 15, 2008 Author Share Posted May 15, 2008 That is what I was thinking Thanks for clarifying it. There is no flippin` way I am going to go recode everything because I named the variables using the "myVar" convention I decided to name my files as follows as well: Php files: myphpfile.php Php files that contain classes: MyPhpFile.php Html files: My_Html_File.html JS : crazy_file.js Link to comment https://forums.phpfreaks.com/topic/105805-naming-conventions/#findComment-542390 Share on other sites More sharing options...
Mr. Despair Posted May 15, 2008 Share Posted May 15, 2008 Php files: myphpfile.php Php files that contain classes: MyPhpFile.php Html files: My_Html_File.html JS : crazy_file.js For filenames I think you should keep them all to lowercase. Link to comment https://forums.phpfreaks.com/topic/105805-naming-conventions/#findComment-542429 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.