Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKnowledgeWoods Consulting
5,607 Points$1 as a variable
Why can't i make $1 or $2 etc. as a variable in PHP?
4 Answers
jne
12,613 PointsYou can't start a variable with a number. See the php manual for more references http://php.net/manual/en/language.variables.basics.php
KnowledgeWoods Consulting
5,607 PointsI read the document but is there any logical reason behind doing it?
Chris Shaw
26,676 PointsThe main reason is simply naming conventions, a large percentage of today's popular languages such as PHP, JavaScript, Ruby etc. all require a variable be started with a valid symbol or letter as that is what their compilers are designed to look for where as a number is a literal value therefore the compiler would see it as invalid code because it's not a name but something that be assigned as an value.
thomascawthorn
22,986 PointsTo follow on, it would be flipping confusing to have
5 = 10;
Although this post refers to a language that doesn't require a '$' sign to assign variables, php still follows the same naming convention to avoid confusing both man and machine.
KnowledgeWoods Consulting
5,607 PointsThanks alot
Adam Roddick
Courses Plus Student 5,935 Pointsnp