Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am reading zend Framework quick start:

There is a function in the Mapper class:

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 dont understand the meaning or relevance of having a class name as an argument, nor can I see how such a thing is allowed in php5 since there is no reference in the php.net manual.

like image 627
Tommy Cox Green Avatar asked Dec 09 '22 12:12

Tommy Cox Green


1 Answers

This is type hinting in action. The function save will only accept an instance of Application_Model_Guestbook as an argument. If you try to pass anything else, PHP will complain.

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

like image 89
deceze Avatar answered Dec 12 '22 01:12

deceze