Forum rules

Please read our Guide to Making Ozzu Tutorials if you would like to submit your own tutorials.

TUTORIAL: Naming Variables

  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7128
  • Loc: Ozzuland
  • Status: Offline

Post August 11th, 2009, 7:43 pm

Naming Variables - Introduction


This is a small and basic tutorials on how to name your variables... what you can, and what you can't. This could be important.

Please take note, that these rules that apply to naming your variables could very well apply to other naming rules such as naming functions and classes (covered in a later tutorial).

What to do/Not do


Names of variables, functions and classes are to start with a letter... any letter from a to z or A to Z or an underline but no numbers and definately no signs. Below is a list of example names that are correctly named and incorrectly names.

  • $Al34n_3
    • Correct
  • $_3fg
    • Correct
  • $3fv_f
    • Incorrect
  • $fg_#t
    • Incorrect
  • function _()
    • Correct (Yet, I don't recommend it)

The only characters allowed in variable, function and class names are any letters (lowercase or uppercase) or and underline followed by any numbers. Of course you could only have letters or letters mixed with numbers or underlines.

Even though you can have a function named _, I don't recommend it... why? Well, this brings us to the next section.

Naming Variables, functions, classes


The reason I don't recommend you to name a function simply by an underline (_) is because it doesn't describe the function any. I recommend you that you name the variable, function, or class in a way that describes what it's holding in one or two words... that is where the underline comes in.

Lets say that you have a variable holding someone's name... you wouldn't name it $city would you? (Unless it's a city's name), you would name it either $persons_name or simply $person...

Conclusion


Well, I hope that you learned the correct way to name your variables, functions, and classes correctly in this short tutorial. Take care :)
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post August 11th, 2009, 7:43 pm

Post Information

  • Total Posts in this topic: 1 post
  • Moderator: Tutorial Writers
  • Users browsing this forum: No registered users and 1 guest
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.