Strawberry
Strawberry

Reputation: 67868

Why do I see underscore prefixed in front of functions and variables in PHP?

Is this a convention of some sort? I'm looking through some code, and at first I thought it might have been for private scopes, but that doesn't seem to be the case. I know double underscore is for PHP's magic methods, but I am not sure why the author of this Recurly library (https://github.com/recurly/recurly-client-php) is using underscores in front of functions and variables. Could someone please explain this to me?

Upvotes: 2

Views: 3618

Answers (2)

zerkms
zerkms

Reputation: 254886

It is a convention that means that the method/property is private

PS: as long as it is just a convention it could be applied to protected and anything else as well

EDIT 5/2016

This is now not recommended, see this

Upvotes: 7

scaraveos
scaraveos

Reputation: 1006

Looks like he was only using "var" some months ago and recently started an effort to replace those with "public/private/protected". From what I understand his code is just not consistent.

But for the history the underscore (_) is a convention for specifying that this method or variable is private or protected.

Upvotes: 1

Related Questions