Jump to content

[SOLVED] PHP Classes? Public, Private, Protected functions? ::?


Dale_G

Recommended Posts

Hey again!

 

Basically I was wondering about classes in PHP. I've heard about different types of functions, public private and protected and I've noticed in some classes people use '::' alot.

 

So I was just wondering if someone could explain a little bit about classes and such, maybe write a really quick dummy class to help show what each type of function does maybe? But any help would be appreciated!

Link to comment
Share on other sites

public, private and protected are not functions but called visibility keywords. It allows you to control how items (methods and properties) can used within an object

 

public means an item can be used anywhere

private means that an item can used within the class it is defined in, or the class it is inherited from.

protected means the item can only be used within the class it is defined in

 

php.net has very good examples of how these are used, here

 

:: is the scope resolution operator, here is an explanation

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.