Php 无法在Symfony 2.0.9上实现NormalizableInterface

Php 无法在Symfony 2.0.9上实现NormalizableInterface,php,symfony,Php,Symfony,我正在尝试使用Symfony 2.0.9实现Symfony\Component\Serializer\Normalizer\normalizable接口 我添加了如下实现: class MRoute implements NormalizableInterface{ ... public function normalize($object, $format = null) { $points = array(); foreach ($this->getPoints()

我正在尝试使用Symfony 2.0.9实现Symfony\Component\Serializer\Normalizer\normalizable接口

我添加了如下实现:

class MRoute implements NormalizableInterface{
...
public function normalize($object, $format = null)
{
     $points = array();
     foreach ($this->getPoints() as $point) {
         $points[] = $point->normalize();
     }
    return array(
        'id' => $this->getId(),
        'name' => $this->getName(),
        'points' => $points

    );
}

/**
 * @see
 */
function denormalize(NormalizerInterface $normalizer, $data, $format = null)
{
    if (isset($data['name']))
    {
        $this->setName($data['name']);
    }

    if (isset($data['id']))
    {
        $this->setId($data['id']);
    }
}
但当我尝试访问web服务时,会出现如下错误:

class MRoute implements NormalizableInterface{
...
public function normalize($object, $format = null)
{
     $points = array();
     foreach ($this->getPoints() as $point) {
         $points[] = $point->normalize();
     }
    return array(
        'id' => $this->getId(),
        'name' => $this->getName(),
        'points' => $points

    );
}

/**
 * @see
 */
function denormalize(NormalizerInterface $normalizer, $data, $format = null)
{
    if (isset($data['name']))
    {
        $this->setName($data['name']);
    }

    if (isset($data['id']))
    {
        $this->setId($data['id']);
    }
}
致命错误:MyGIS\GISBundle\Entity\MRoute::normalize()的声明必须与第16行C:\NetbeansProjects\MRoute\u rest\u service\src\MyGIS\GISBundle\Entity\MRoute.php中的Symfony\Component\Serializer\Normalizer\NormalizableInterface::normalize()的声明兼容

我打开了Symfony\Component\Serializer\Normalizer\NormalizableInterface.php,签名匹配


我做错了什么?

v2.0.9中的界面与您在此处粘贴的界面大不相同:

看起来您已经实现了2.1接口,这是完全不同的:

如果您实际上正在使用2.1(主分支),则需要为
NormalizerInterface
添加
use
语句

use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

非常感谢。问题是,我在使用[SymfPony]()中的一个示例进行web服务,它一定使用了以前的版本。将签名切换为与2.0.9 NormalizableInterface.php完全匹配,问题就解决了。