开发者

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->getEma开发者_运维问答il(),
        '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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜