3

Possible Duplicate:
What's the deal with a leading underscore in PHP class methods?

I think it's pretty descriptive... what does it mean if you see a function starting with an underline in php? I've seen it many times and I still don't know what it is! It still works but it just looks weird starting with an underline and I suspect it's just a convention but I don't know what it is. I am not talking about double underlined functions ( i.e. __construct()) but a single underline.

My best guess is that it means it's your own unique function and you want others to know that?

Community
  • 1
  • 1
netrox
  • 5,224
  • 14
  • 46
  • 60
  • gee, i'd think stackoverflow would let me have the final say in closing this since the duplicate much answered my question. :/ I just closed it... one more needed. – netrox May 28 '11 at 04:48
  • It's all good, you can just accept an answer. I believe this can be merged sometime in the future when it gathers enough close votes (or not). Either way, it's still useful and these answers are correct. Here's another: [About PHP underscore naming convention (as in "_method" or "_property")](http://stackoverflow.com/q/5766138) – Wesley Murch May 28 '11 at 04:51

2 Answers2

12

There's no significance as far as the language itself is concerned, but a single-underscore prefix is usually used to indicate "private" or "hidden" class members.

Sometimes you see the underscore prefixed to all private and protected members, just to make it more obvious that they aren't publicly available. Other times, regardless of the access level, an underscore can indicate an "internal" function, one that can technically be used, but the use of which is discouraged.

John Flatness
  • 32,469
  • 5
  • 79
  • 81
5

Generally, programmers use a leading underscore in functions to indicate that this is an internal (not meant to be invoked from outside) function and if it were possible they would have made it private.

Its just a practice. Generally speaking, programming languages that allow a function name to begin with underscore do not treat them differently from other functions in any way. Even if a language allows you to explicitly make a function private, people may still use this convention habitually.

Salman A
  • 262,204
  • 82
  • 430
  • 521