Static or public functions inside a class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smasher
Forum Commoner
Posts: 38
Joined: Fri Apr 20, 2007 5:22 am

Static or public functions inside a class

Post by Smasher »

Can anyone define the difference? I cant seem to produce any different results between using the two.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Smasher
Forum Commoner
Posts: 38
Joined: Fri Apr 20, 2007 5:22 am

Post by Smasher »

Okay so

static is essentially used for functions inside a class that will be called on there own without an instance of the class
static can be put before both public and private.

public are functions that can access anything within the class
private are for functions or vars within the class that cant be called from anywhere but within that class

Thanks.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Exactly, only the static keyword is placed after the visibility keyword

Code: Select all

public static function funcName() {
edit: oops, forgot "function" (thanks d11)
Last edited by aaronhall on Wed Apr 25, 2007 11:42 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Yes, ordering goes:

[final|abstract] [public|private|protected|var] [static] [function|$]name
Post Reply