Loading video...
Classes vs. Objects
- A class provides a definition for a user-defined data type. An object is an instance of a class providing values to a class’s properties.
- Each instance of a class has their own ‘version’ of a class’s properties, and these are referred to as instance properties.
- Static properties are class properties whose values are shared between all of the instances of a particular class.
- A property is declared static in a class definition by using the
statickeyword:public static $numPeople = 0;
- An object of a class does NOT need to be instantiated to access a class's static properties.
- The scope resolution operator (
::) is used to access static properties. - A public static property is accessed from outside of a class definition using the syntax:
Person::$numPeople; // uses the class name
- A static property, whether public or private, can be accessed inside a class definition with an
alternative syntax that uses the
selfkeyword:self::$numPeople;
- A static property CANNOT be accessed via an object instance variable using the
->operator. -
Static methods are methods defined in a class that are at the class-level and are NOT associated with
particular instances of a class. They are declared with the
statickeyword:public static function add($op1, $op2) {…
- Static methods CANNOT use the
$thisvariable within their definitions. - Non-static methods are referred to as instance methods.
- Static methods are called using the scope resolution operator (externally using the class name, and internally
using the
selfkeyword):- Externally:
Person::getClassName() - Internally:
self::getClassName()
- Externally:
- A class constant is a constant defined within a class definition that is specific to that class. They
are defined using the
constkeyword:const PI = 3.14;
- They are accessed using the scope resolution operator (with no
$prepending their name):- Externally:
Math::PI - Internally:
self::PI
- Externally:
- Additional Resources:
Classes vs. Objects
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.
- Intro
- Lesson Overview
- Class vs. Object Review
- Static Properties
- Scope Resolution Operator (::)
- Scope Resolution Operator (::) & Static Property
- Coding Example: Accessing a Static Property Using the Scope Resolution Operator
- Coding Example: Accessing a Static Property in a Class Definition
- Coding Example: Using a Static Property as an Instance Counter
- Static Methods
- Classes vs. Objects
- Class Constants
- Homework Challenge
- Homework Challenge (cont.)

































Start Learning Now
Our free lessons will get you started (Flash® 10 required).
Sign up for Educator.comGet immediate access to our entire library.
Features Overview