I have a class called Plato that extends Producto witch contains de atribute precio. The setter is defined here:
public function setPrecio(\double $precio)
{
$this->precio = $precio;
return $this;
}
And I trying to add a new element to the DB with:
$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();
It gives me the following error message:
Catchable Fatal Error: Argument 1 passed to
Servinow\EntitiesBundle\Entity\Producto::setPrecio() must be an
instance of double, double given, called in
/Users/luis/git/servinowServer-luis/src/Servinow/EntitiesBundle/Entity/PlatoRepository.php
on line 41 and defined in
/Users/luis/git/servinowServer-luis/src/Servinow/EntitiesBundle/Entity/Producto.php
line 169
Modify
setPrecio()function in that wayYou could use something like that
for type control, before set it into
$thisRemember that