How to call parent function from instance of child?

How to call parent function from instance of child?

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

Stefan Bogdanescu

Founder & Senior Architect

Calling Parent Methods in Overridden Functions

When you override a method in a child class like User, the default behavior is to execute your new implementation completely, ignoring what lies beneath it in the parent class BaseUser. This is how inheritance and polymorphism are meant to work. However, there are specific scenarios where you need to retain the original logic of the parent while adding your own custom behavior before or after it runs.

In your case, you have defined a delete method in the User class that currently does nothing. If you simply want to execute the parent's delete functionality but also perform some cleanup tasks specific to your User model, you must explicitly invoke the parent's method.

The Syntax for Invoking Parent Methods

To call the delete function from the BaseUser class within the User class, you use the parent:: prefix followed by the method name. This is a standard mechanism in object-oriented programming languages like PHP, allowing you to access inherited members that might otherwise be shadowed.

Here is how your code should look:

class User extends BaseUser {
    public function delete() {
        // Perform custom logic before deletion
        $this->logDeletionRequest();
        
        // Call the parent's delete implementation
        return parent::delete(); 
    }
}

In this example, when you execute $user->delete(), PHP executes your code inside the User class first. It logs the request (whatever that entails in your application), and then it calls parent::delete(). This ensures that the core deletion logic defined in BaseUser is not bypassed.

Returning Values and Side Effects

It is crucial to consider what your overridden method returns. In Laravel, the Model trait provides a default implementation for delete that returns true on success or false on failure. If you override this method without calling the parent, you break the contract expected by other parts of your application.

If your custom logic in User::delete() throws an exception or returns a specific status code before calling the parent, ensure that the return value of parent::delete() is propagated correctly. Failing to pass the result back can lead to silent failures where the database record remains untouched even though your code thinks it was deleted.

Common Pitfalls in Inheritance Chains

Your project structure mentions a separate UserTable class. It is important to clarify how this fits into the inheritance hierarchy. If UserTable is intended to be an Eloquent model (or a custom implementation of one), it should extend BaseUser, not exist alongside it as a separate table definition object.

If you are using the Laravel framework, the standard practice is to define your models in files like App\Models\User.php. The class name usually matches the database table name (excluding the prefix). Ensure that BaseUser contains the actual logic for deletion and that User extends it correctly.

Attempting to call the parent method without the parent:: keyword will result in a fatal error because PHP cannot find a method named delete within the current class scope if only your version exists there. Always verify that the parent class actually defines the method you intend to override; otherwise, the inheritance chain is incomplete.

When Not to Override

Before deciding to override delete, ask yourself if you truly need to intercept the process. Sometimes it is cleaner to use event listeners or hooks provided by the framework (like Laravel's deleted event) to handle custom logic after the record is removed. Overriding core methods like delete can make debugging difficult and may cause issues if you upgrade your base library or framework version, as internal implementations might change.

If you find yourself frequently needing to customize delete behavior, consider whether a trait or an interface would provide a more maintainable solution than direct method overriding in every child class.

Our network