在函数中传递类名作为参数意味着什么?
我正在阅读 zend Framework 快速入门:
Mapper 类中有一个函数:
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));
}
}
我不明白以类名作为参数的含义或相关性,也看不到 php5 中如何允许这样的事情,因为没有参考在 php.net 手册中。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是实际的类型提示。函数
save
仅接受Application_Model_Guestbook
实例作为参数。如果您尝试传递任何其他内容,PHP 会抱怨。http://php.net/manual/en/language.oop5.typehinting.php
This is type hinting in action. The function
save
will only accept an instance ofApplication_Model_Guestbook
as an argument. If you try to pass anything else, PHP will complain.http://php.net/manual/en/language.oop5.typehinting.php