Skip to Content
Learn
Classes and Objects
Review

Now you have the knowledge to create your own classes and objects in PHP using OOP! Take some time to review the concepts before moving on:

  • Classes are defined using the class keyword.
  • Functions defined within a class become methods and variables within the class are considered properties.
  • There are three levels of visibility for class members:
    • public (default) - accessible from outside of the class
    • protected - only accessible within the class or its descendants
    • private - only accessible within the defining class
  • Members can be defined to be static.
    • Static members are accessed using the Scope Resolution Operator (::).
  • Classes are instantiated into objects using the new keyword.
    • Members of an object are accessed using the Object Operator (->).

Instructions

We’ve included some examples of using classes in PHP. Use this space to play around with the concepts and move on when you are ready.

Folder Icon

Take this course for free

Already have an account?