开发者

what does underline before function mean in php? [duplicate]

This question already has answers here: Closed 11 years ago.

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开发者_如何学Go 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜