Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.