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 Build a Simple PHP Application Working With Functions Introducing User-Defined Functions

Ian Hilton
Ian Hilton
6,223 Points

If you have a variable that you want to be a count, why would you name it $count?

If you have a variable that you want to be a count, why would you name it $count? Why would you risk confusing it with the count function? Why not name it $m_count or $fm_count or anything other than count?

2 Answers

Steven Griffiths
Steven Griffiths
3,165 Points

I agree with Ian. It would make it less confusing when teaching beginners of programming not to give variables identical names in these situations.

It's the kind of thing that really can confuse something that could be considered simple.

My take on it is to name your variable in anyway that make sense to you or something that is convenient, as long its not a reserve word or starting with a number.

I have seen count variable as $i, $j $x, $ct. Often use in loops. Comments can be inserted as reminder and avoid any confusion.

For beginners, video and books often uses $count because it easy to understand and is intuitive.