'Doctrine simple_array returns one empty element instead of empty array
I noticed that an entity field of type simple_array does not return the correct value for empty string.
Entity:
namespace MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* MyEntity
*
* @ORM\Entity(repositoryClass="MyBundle\Repository\MyEntityRepository")
* @ORM\InheritanceType("SINGLE_TABLE")
*/
class MyEntity
{
/**
* @var string
*
* @ORM\Column(type="simple_array", nullable=true)
*/
private $myList;
/**
* Get myList
*
* @return array
*/
public function getMyList()
{
return $this->myList;
}
}
Code:
$data = $em->getRepository("MyBundle:MyEntity")->find($recordId);
print_r($data->getMyList());
If myList
in the database is an empty string (not NULL, already trimmed), why doctrine returns this:
Array
(
[0] =>
)
instead of this?
Array
(
)
It act as I expect if the value is NULL but NULL and empty should be both evaluated as false, isn't true?
I'm using Symfony 2, there is a way to fix that?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|