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 (->).


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.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?