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

Posted by nocash on Stack Overflow See other posts from Stack Overflow or by nocash
Published on 2009-03-19T18:04:31Z Indexed on 2010/04/08 18:53 UTC
Read the original article Hit count: 148

Filed under:
|
|
|

While looking over various PHP libraries I've noticed that a lot of people choose to prefix some class methods with a single underscore, such as

public function _foo()

...instead of...

public function foo()

I realize that ultimately this comes down to personal preference, but I was wondering if anyone had some insight into where this habit comes from.

My thought is that it's probably being carried over from PHP 4, before class methods could be marked as protected or private, as a way of implying "do not call this method from outside the class". However, it also occurred to me that maybe it originates somewhere (a language) I'm not familiar with or that there may be good reasoning behind it that I would benefit from knowing.

Any thoughts, insights and/or opinions would be appreciated.

© Stack Overflow or respective owner

Related posts about coding-style

Related posts about php