Bitto Bennichan Bitto Bennichan - 6 months ago 13
PHP Question

variable names- why should it begin with a letter or an underscore?

In most of the programming languages variable names should begin with a letter or an underscore, followed by any combination of letters, numbers, and the under-score character. I have found this in c,c++ and php (after the $).

  1. Is it just a convention followed by compiler/interpreter writers or are there any practical reasons for this?

  2. Why is it necessary that variable names be composed only of letters,underscore and numbers in these languages?

a3f a3f
  1. It would be ambiguous whether 4U is an integer or an identifier. This assumes that 4 on its own would be an invalid identifer.
  2. #include, a*a and other constructs would be ambiguous.

_ isn't used as operator and a word beginning with [A-Za-z_] in C is either a predefined keyword or an identifier. No ambiguity possible.