Php polymorphism - calling a parent function in a polymorphic child function

Here's the parent class:

    class Event {

    public function getLang($lang){
     $sql = "select * from Event where EventID =" . $this->EventID . "AND Lang =" . $lang;
    $result = $this->selectOneRow($sql);
    }
}

and here is the child:

class Invitation extends Event{

public function getLang($lang){
Event::getLang($lang);

$sql = "select * from invitation where EventID =" . $this->EventID . " and Lang = " . $lang;

    }
}

I had hope that EVENT :: getLang ($ lang) would work, but after I repeat the request, I see that it ends with EventID.

Is there a proper way to do this?

I tried to copy / paste the code into the child element directly, but this will not work, because I got the variables at the parent level, which will be assigned the result of the event selection.

Is there a way around this or am I at a dead end?

+3
source share
3 answers

I think you want to use the keyword parent:

class Invitation extends Event{
    public function getLang($lang){
       parent::getLang($lang);

       $sql = "SELECT * FROM invitation WHERE EventID =" . $this->EventID . " AND Lang = " . $lang;
    }
}
+5
source

You have to use parent

class Invitation extends Event{

    public function getLang($lang){
        parent::getLang($lang);
        ....
    }
}

Event::getLang($lang); getLang . . :

(::)

Parent

0

, Event::getLang() parent

parent::getlang($lang);

Update: I meant that with Event::getLang()you usually call a static method in a class, which may or may not be extended. Where it parent::method()always calls the inherited method and saves the scope (class or static) of the calling method, it Classname::method()always tries to call the static method for a particular class.

0
source

Source: https://habr.com/ru/post/1793841/


All Articles