OOP Cheatsheet

This is a small OOP (Object oriented programming) cheatsheet, to give a quick introduction to some of the commonly used OOP terminology.

function returnSomething() {
    $something = 'something';

    return $something;

echo returnSomething();

class Something {
    protected $somethingElse = 'something else';

    public function returnSomethingElse() {
        return $this->somethingElse;

$something = new Something();

echo $something->returnSomethingElse();
1FunctionA function is defined in the global namespace and can be called from anywhere.
2VariableThe variable is enclosed in the function definition, so it can only be used by that function.
4Variable accessHere the value contained in the variable is accessed.
7Function callThis executes the function.
9Class definitionA class is a blueprint that you can generate objects from. All new objects based on a class will start out with everything that has been defined in the class definition.
10PropertyA property is like a variable, but is accessible from the entire object it is defined in. Objects can have different visibilities.
12MethodA method is a function defined inside a class. It is always accessible to all objects of the class, and depending on it's visibility it might, or might not, be accessible from outside the class.
13Property usageAn object can reach it's own properties using the `$this->` syntax.
17Object instantiationThis is an object is created based on a class definition.
19Method callThe method `Something::returnSomethingElse()` is called on the newly created object. The method has it's visibility set to "public", hence it can be called from outside the object itself.
21Property accessThis is how the property `Something::$somethingElse` is accessed from outside the object. But in this case the property has the visibility protected which means it can't be accessed from outside the object itself, hence this will cause PHP to fail.