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 trial

PHP PHP Basics (Retired) PHP Data & Structure PHP Variables

Underscore vs Dash

Just a curiosity question, based on my personal preference: why doesn't PHP support dashes for naming conventions? I experimented with using $full-name="Mike The Frog"; instead of $full_name="Mike The Frog";, but I found that the preview page couldn't display when I used the dash instead of an underscore.

Wilhelm LΓΆwe
Wilhelm LΓΆwe
4,603 Points

Hi Angela, i gave it a quick try and research and found that a dash in variable names does not work / is not allowed in my working version of PHP. I think it is because the dash in PHP is also the subtraction operator. I use underscores or camelCase names.

Thank you! :)

2 Answers

Kyaw Kyaw Soe
Kyaw Kyaw Soe
7,528 Points

PHP doesn't allow to use dash (-) and can't start with number digit(1-9) for naming variable

Thank you! :)

Aaron Munoz
Aaron Munoz
11,177 Points

I don't know of any language that allows dashes quite honestly.

JavaScript allows for both dashes and underscore, and I got used to using dashes in my coding process :) One less key to press! So now I'm just re-training my fingers' default actions when I type.

Aaron Munoz
Aaron Munoz
11,177 Points

Wow, been so long that I forgot that about JS. I use underscores all around for that reason.