How to call super in PHP?

How to call super in PHP?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Calling parent::method() in PHP: A Practical Guide

In Object-Oriented design, you often need to reuse logic from a parent class while adding specific behavior for a child class. This pattern is familiar to developers coming from languages like Objective-C or C#, where the syntax for accessing the super implementation is implicit or handled via super. In PHP, the equivalent mechanism exists, but it requires explicit syntax that differs slightly from those ecosystems.

When you define a method in a subclass that shares the same name as a method in its parent class, the child version overrides the parent version by default. If your goal is to execute the parent's logic at the beginning—or end—of your child's implementation before continuing with your own code, you must explicitly invoke the parent method. PHP provides a specific syntax for this: parent::methodName().

Consider a scenario where classA defines a method fooBar() that performs some initialization or logging, and classB extends classA but needs to perform additional steps after that initialization. Here is how you structure the inheritance:

<?php
class classA {
    public function fooBar() {
        echo "Executing logic from classA\n";
        // Additional parent logic here
    }
}

class classB extends classA {
    public function fooBar() {
        // Call the parent implementation explicitly
        parent::fooBar();
        
        // Continue with child-specific logic
        echo "Executing additional logic in classB\n";
    }
}

In this example, calling parent::fooBar() inside classB::fooBar() ensures that the code block within classA runs first. This is the direct PHP equivalent to the super keyword behavior found in Objective-C. It allows you to maintain a chain of responsibility without duplicating logic or breaking encapsulation.

It is important to distinguish between parent:: and self::. The self keyword refers to the class where the code is currently defined, regardless of inheritance. If you were to use self::fooBar() inside classB, it would simply call classB::fooBar() recursively or fail if not defined statically in a way that bypasses the override, leading to infinite recursion or unexpected behavior. Only parent:: looks up the actual class in the inheritance hierarchy immediately above the current class.

Handling Private and Protected Methods

While parent:: works seamlessly with public methods, you must be aware of visibility modifiers when trying to call parent methods. If the method defined in classA is marked as private, it cannot be accessed from classB using parent::fooBar(). Private methods are strictly scoped to the class they are defined in, and attempting to call them from a subclass results in a fatal error.

Conversely, if the parent method is protected, you can access it via parent::, provided there are no other overriding layers between the child and the grandparent that might interfere. This restriction enforces strict encapsulation, ensuring that internal implementation details of a class remain hidden unless intentionally exposed through protected interfaces or public wrappers.

Static Context Considerations

There is a subtle but critical distinction when invoking parent methods in static contexts. If you define fooBar() as a static method, the scope resolution operator :: applies to the class name itself. In this case, parent::fooBar() works correctly because it resolves to the static method of the direct parent class. However, if you attempt to call a non-static method on a static context, PHP will throw an error unless the method is explicitly defined as static in the hierarchy.

When designing your architecture, ensure that the methods you intend to chain via parent:: have consistent visibility and static definitions across the inheritance tree. Mixing static and non-static calls across parent-child relationships can lead to confusing runtime errors that are difficult to debug without a clear understanding of where the method was originally defined versus where it is being invoked.

For developers working within the Laravel framework, this pattern is particularly relevant when extending Eloquent models or Service Providers. While you might rarely need to override core methods directly, understanding how parent:: functions allows for cleaner extensions without relying on trait hacks or magic methods that obscure the inheritance chain.

Our network