4

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
Tommy Cox Green
  • 633
  • 1
  • 4
  • 20
  • Quick note, your title is slightly inaccurate. You probably meant to ask 'What does providing a class name when declaring function parameters mean?' – Ali Nov 21 '10 at 12:53

1 Answers1

14

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

deceze
  • 510,633
  • 85
  • 743
  • 889