我有一个叫柏拉图的类,它扩展了包含精确性的积。在这里定义了设置者:
public function setPrecio(\double $precio)
{
$this->precio = $precio;
return $this;
}我试图在DB中添加一个新元素,包括:
$plato = new Plato;
$em = $this->getEntityManager();
// I have tryed this three ways to insert
$plato->SetPrecio(doubleval($precio));
$plato->SetPrecio((double) 2);
$plato->SetPrecio(2.0);
$em->flush();它提供了以下错误消息:
可捕获的致命错误:传递给Servinow\EntitiesBundle\Entity\Producto::setPrecio()的参数1必须是双给定的实例,在第41行的/Users/luis/git/servinowServer-luis/src/Servinow/EntitiesBundle/Entity/PlatoRepository.php中调用,在/Users/luis/git/servinowServer-luis/src/Servinow/EntitiesBundle/Entity/Producto.php第169行中定义
发布于 2012-12-06 14:11:03
用这种方式修改setPrecio()函数
public function setPrecio($precio)
{
$this->precio = $precio;
return $this;
}你可能需要这样的东西
gettype($precio)[...];
if(is_numeric($precio))[...];对于类型控制,在将其设置为$this之前
记住这一点
类型提示只能是对象和数组(因为PHP5.1)类型。不支持使用int和string提示的传统类型。
https://stackoverflow.com/questions/13745089
复制相似问题