How to call parent function from instance of child?

前端 未结 6 2059
青春惊慌失措
青春惊慌失措 2021-02-18 17:57

I have model

BaseUser.class.php
User.class.php
UserTable.class.php

In user Class I have been override the delete function

6条回答
  •  梦毁少年i
    2021-02-18 18:55

    It can be done using call_user_func. Yes, its bad practice, but its possible.

    class BaseUser {
        public function delete()
        {
            echo 'BaseUser deleted';
        }
    }
    
    class User extends BaseUser{
        public function delete()
        {
            echo 'User deleted';
        }
    }
    
    $instance = new User();
    
    call_user_func(array($instance, 'parent::delete'));
    

    result:

    BaseUser deleted
    

提交回复
热议问题