Zend framework2 Zend Framework 2:PostService::savePost()必须与Blog\Service\PostServiceInterface::savePost(Blog\Model\PostInterface$Blog)问题兼容
我在Zend Framework 2中使用链接添加博客文章时遇到了这个问题。我已经仔细检查了我是否遗漏了什么。有谁能帮我解决我哪里出了问题,或者哪里缺了什么。因为我是新的Zend框架,所以跟踪这个问题有点困难Zend framework2 Zend Framework 2:PostService::savePost()必须与Blog\Service\PostServiceInterface::savePost(Blog\Model\PostInterface$Blog)问题兼容,zend-framework2,Zend Framework2,我在Zend Framework 2中使用链接添加博客文章时遇到了这个问题。我已经仔细检查了我是否遗漏了什么。有谁能帮我解决我哪里出了问题,或者哪里缺了什么。因为我是新的Zend框架,所以跟踪这个问题有点困难 Fatal error: Declaration of Blog\Service\PostService::savePost() must be compatible with Blog\Service\PostServiceInterface::savePost(Blog\Model\P
Fatal error: Declaration of Blog\Service\PostService::savePost() must be compatible with Blog\Service\PostServiceInterface::savePost(Blog\Model\PostInterface $blog) in D:\xampp\htdocs\zf\module\Blog\src\Blog\Service\PostService.php on line 9
修复此错误所需的文件如下所示:
<?php
// Filename: /module/Blog/src/Blog/Service/PostService.php
namespace Blog\Service;
如果我看到的是正确的,那么在下面的示例中,在
PostServiceClass
中,一个use Blog\Model\posterface缺少代码>子句
这导致savePost
方法中使用的posterface
是Blog\Service\posterface
而不是Blog\Model\posterface
,因此savePost
方法的实现与其在接口中的声明不兼容
use Blog\Mapper\PostMapperInterface;
class PostService implements PostServiceInterface {
/**
* @var \Blog\Mapper\PostMapperInterface
*/
protected $postMapper;
/**
* @param PostMapperInterface $postMapper
*/
public function __construct(PostMapperInterface $postMapper) {
$this->postMapper = $postMapper;
}
/**
* {@inheritDoc}
*/
public function findAllPosts() {
return $this->postMapper->findAll();
}
/**
* {@inheritDoc}
*/
public function findPost($id) {
return $this->postMapper->find($id);
}
/**
* {@inheritDoc}
*/
public function savePost(PostInterface $post) {
return $this->postMapper->save($post);
}
}