What does passing a class name as a parameter in a function mean?

I read the zend Framework quick launch:

The Mapper class has a function:

public function save(Application_Model_Guestbook $guestbook)
{
    $data = array(
        'email'   => $guestbook->getEmail(),
        'comment' => $guestbook->getComment(),
        'created' => date('Y-m-d H:i:s'),
    );

    if (null === ($id = $guestbook->getId())) {
        unset($data['id']);
        $this->getDbTable()->insert($data);
    } else {
        $this->getDbTable()->update($data, array('id = ?' => $id));
    }
}

I don’t understand the meaning or relevance of having a class name as an argument, and I don’t see how this is allowed in php5 since there is no link in the php.net manual.

+3
source share
1 answer

This is a type hinting at action. The function savewill only accept an instance Application_Model_Guestbookas an argument. If you try to pass something else, PHP will complain.

http://php.net/manual/en/language.oop5.typehinting.php

+12
source

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


All Articles