---
title: Do Not Ignore Superclass Logic
impact: HIGH
impactDescription: ensures proper inheritance behavior and prevents breaking base logic
tags: inheritance, override, superclass, oop, quality, php
---

## Do Not Ignore Superclass Logic

When overriding methods in a subclass, ensure that you are not accidentally bypassing critical logic defined in the base class. Unless you intentionally want to replace the entire behavior, you should generally call the parent implementation.

**Incorrect (ignoring superclass logic):**

```php
class BaseService {
    public function save($entity) {
        $this->validate($entity);
        $this->beforeSave($entity);
        $this->repository->persist($entity);
        $this->afterSave($entity);
    }
}

class UserService extends BaseService {
    public function save($user) {
        // Completely bypasses validation and hooks!
        $this->repository->persist($user);
    }
}
```

**Correct (calling parent implementation):**

```php
class UserService extends BaseService {
    public function save($user) {
        // Add subclass-specific logic
        $user->updated_at = now();

        // Call superclass logic to ensure hooks and validation run
        parent::save($user);

        // Add more specific logic
        $this->notifyAdmins($user);
    }
}
```

**When is it acceptable to skip `parent::method()`?**
- When the base implementation is explicitly designed to be replaced.
- When the base implementation is an empty placeholder or default behavior that does not apply.
- **Action**: Always document the reason why the parent logic is being intentionally bypassed.

**Tools:** PHPStan (check for missing parent calls), Psalm, PR review
