Variable name length

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm working on a new project that I want to get as human readable as
possible, and was wondering what the constraint on variable naming does
PHP have.

Can I have a variable like:


(34 characters if you want to know)

Also any idea if there is a similar limit to MySQL or Postgre field

I've been coding for decades back when I had a limit of 2 characters
for variables on the old Commodore VIC-20, it's kind of hard to get
used to all this room.  I've tried to find my answer in TFMs, but
nothing really goes into that metric, I figure you PHP code masters
would know of any (or possible pitfalls) if it bit you once.

Thanks for any insight,

Re: Variable name length

I don't see why not.  However, usually, 34 characters is not all that  
readbable.  Some shorthand can be used for things that ANY programmer would  
know (jpg, img, db, eml, tbl, etc.).

The biggest concerning is value length(characters to 255, etc.).

Hope it helps,

Quoted text here. Click to load it

Re: Variable name length

Hash: SHA1 wrote:

Quoted text here. Click to load it
Quoted text here. Click to load it

Congratulations! You have just been awarded with a wonderful RTFM: :-P :
"A valid variable name starts with a letter or underscore, followed by *any*
number of letters, numbers, or underscores."

- --  
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net
Version: GnuPG v1.4.2 (GNU/Linux)


Re: Variable name length

Didn't find the MySQL one at all; and I didn't see a number in the PHP
reference which I did see, so I missed that too.  But "any number of
characters" is intriguing.  I did a test and created a test string
variable called:
And added text to it (it worked) then created:
 and echoed both back, both were unique..

Impressive, but I think probably some sort of abbreviation for such
long identifiers would be necessary for sanity's sake.

That was a sufficient test but I am still tempted to write up a 32k
variable name to see if it will still stand true.  ;-)

Thanks for pointing out the obvious that I missed!


Site Timeline