S
S
Sergey Fedotov2014-04-14 05:52:09
PHP
Sergey Fedotov, 2014-04-14 05:52:09

PHP: how to call a method from a parent class that we have overridden?

Let's say we have a parent class:

class ParentClass {   
   protected $field;   
   public function showField() {
      print($field);   
   }
}

And there is a child class:
class ChildClass extends ParentClass {
   public function showField() {
      /* ... code ... */   
      /* Вызов метода showField() из родительского класса */
      /* ... code ... */
   }
}

The question itself is: how to call the showField method from the parent class ParentClass in the child class ChildClass ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evgeny Komarov, 2014-04-14
@lechie-dev

Use language construct
parent::showField();

O
onogur, 2014-04-14
@onogur

Create an instance of the parent class?

1
1001001 111, 2014-04-14
@IgorO2

Could be so,$this->showField();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question