How to call parent function from instance of child?

Technically this is not possible from the "outside" (the public interface) for good reason.

If you have understood why (otherwise read below), and you actually know what you do, there is no reason to actually not offer the functionality:

class User extends BaseUser {
   ... 
   function parentDelete(){
       parent::delete();
   }
   ...
}

user = new User();
$user->delete();  // will call the overridden delete
$user->parentDelete();     // want to call parent delete

However if you ever do that, you should know that you have misused inheritance somehow. This must be an exceptional situation as I can not imagine any situation where you actually need that to do at all.

So try to formulate why you need that functionality so to give yourself better suggestions.

Why is that bad?

For a very simple reason: In your software you do not need to know that $user has a parent or not. That is some detail you should not care at all about.

That will allow you to replace any user-object you have in your software with a childobject of user later on. This is important as you want to change your software over time.

If you make the internal detail part of the public interface you are robbing yourself the possibility to keep things flexible. Not being flexible is really a bad situation.


maybe try this

parent::delete();

Tags:

Php

Doctrine