/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Need to know

Hello All,

This is not a problem but a couple of questions regarding info that is hard for me to find and define (With examples/Tutorials).

Q1: What is the purpose of the underscore as the first character in the function name? Example: function _functionName()

Q2: Same as Q1 but its the double underscore? Example: __functionName()

I saw a post the other day that had Q1 in the code and wanted to know the use/benefits/features this might have (If any) and some documentation on them.

Thanks

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@SodbusterNov 04.2008 — The double underscore is reserved by php. The manual says (here):PHP reserves all function names starting with __ as magical. It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality.[/QUOTE]The single underscore is usually used to denote private methods in a class.
Copy linkTweet thisAlerts:
@Phill_PaffordauthorNov 04.2008 — Thanks,

Just to clarify the single underscore is just a Naming convention used to identify a private methods in a class or is this something PHP enforces?

So by using the single underscore it would ensure the private methods in a class? is this correct?

Thanks for your fast reply.

I understand the double underscore and have looked at the docs on that (Funny it was hard to find when Googling it)
Copy linkTweet thisAlerts:
@SodbusterNov 04.2008 — Use of the single underscore is merely by convention (or even willy-nilly by some). It's only informative, you might say.

The page on overloading in the manual gives more information relevant to double underscore prefixed methods.
Copy linkTweet thisAlerts:
@Phill_PaffordauthorNov 04.2008 — Thanks big help for me :-)
×

Success!

Help @Phill_Pafford spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...