How to call an original function in an overloaded method in php

1

I need to run the parent version of an overloaded method in php, is it possible?

Ex:

public function delete()
{
    // executa código extra e depois executa o método original
    super->delete();
}
    
asked by anonymous 24.05.2015 / 17:34

2 answers

4

When there are more inheritance levels it may be necessary to use the class name instead of parent , the code snippet below exemplifies the uses for each case.

<?php
class Foo {
    public function exemplo() {}
}

class Bar extends Foo {
    public function exemplo() {
        parent::exemplo(); // chama da classe pai: Foo::exemplo()
    }
}

class Foobar extends Bar {
    public function exemplo() {
        parent::exemplo(); // chama da classe pai: Bar::exemplo()
        Foo::exemplo(); // chama da classe avô
    }
}
    
26.05.2015 / 13:33
0

Yes, use parent::

public function delete()
{
    // executa código extra e depois executa o método original
    parent::delete();
}
    
24.05.2015 / 17:34