Php 实体在学说中的作用

Php 实体在学说中的作用,php,symfony,doctrine-orm,symfony-2.7,Php,Symfony,Doctrine Orm,Symfony 2.7,我试图用条令来坚持我的用户的角色 实体已启动并正在运行,但尝试登录时出现以下错误: RoleHierarchy.php第43行中的FatalErrorException:错误:调用 字符串上的成员函数getRole() 我试着看看这个“字符串”是什么,它是: array (size=1) 0 => string 'Europe/London' (length=13) 这是我的角色实体: namespace AppBundle\Entity; use Doctrine\ORM\Map

我试图用条令来坚持我的用户的角色

实体已启动并正在运行,但尝试登录时出现以下错误:

RoleHierarchy.php第43行中的FatalErrorException:错误:调用 字符串上的成员函数getRole()

我试着看看这个“字符串”是什么,它是:

array (size=1)
  0 => string 'Europe/London' (length=13)
这是我的角色实体:

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\Role\RoleInterface;
use Symfony\Component\Validator\Constraints as Assert;

/**
* Class Role
* @package AppBundle\Entity
*
* @ORM\Entity()
* @ORM\Table("fxm_role")
* @ORM\HasLifecycleCallbacks()
*/
class Role implements RoleInterface
{
/**
 * @var integer $id
 *
 * @ORM\Column( type="integer")
 * @ORM\Id()
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string $role
 *
 * @ORM\Column(type="string")
 */
private $role;

/**
 * @var string $name
 *
 * @ORM\Column(type="string")
 */
private $name;

/**
 * @var \DateTime $created
 *
 * @ORM\Column(type="datetime")
 */
protected $created;

/**
 * @var \DateTime $updated
 *
 * @ORM\Column(type="datetime")
 */
protected $updated;

/**
 * @ORM\PrePersist
 * @ORM\PreUpdate
 */
public function updatedTimestamps()
{
    $this->setUpdated(new \DateTime('now'));

    if ($this->getCreated() == null) {
        $this->setCreated(new \DateTime('now'));
    }
}

/**
 * Get role
 *
 * @return string
 */
public function getRole()
{
    return $this->role;
}
对于用户来说,这里是角色使用的部分

/**
 * @var ArrayCollection $roles
 *
 * @ORM\ManyToMany(targetEntity="Role", cascade={"persist"})
 * @ORM\JoinTable(name="users_roles",
 *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
 *      )
 */
protected $roles;

/**
 * Returns the roles granted to the user.
 *
 * <code>
 * public function getRoles()
 * {
 *     return array('ROLE_USER');
 * }
 * </code>
 *
 * Alternatively, the roles might be stored on a ``roles`` property,
 * and populated in any number of different ways when the user object
 * is created.
 *
 * @return Role[] The user roles
 */
public function getRoles()
{
    return $this->roles->toArray();
}
我真的不知道问题出在哪里,但因为我甚至没有分析器栏,所以出于某种原因,实体甚至没有被加载

角色层次结构也不复杂:

role_hierarchy:
    ROLE_BACKOFFICE: ROLE_USER
    ROLE_ADMIN: ROLE_BACKOFFICE
如果有人知道如何解决这个问题,那就太好了,我已经在这个问题上坚持了一段时间了(而且作为一个实体的角色并没有太多文档)

更新:出于某种奇怪的原因,它曾经给了我角色数组

array (size=1)
  0 => 
    object(AppBundle\Entity\Role)[437]
      private 'id' => int 1
      private 'role' => string 'ROLE_BACKOFFICE' (length=15)
      private 'name' => string 'Back Office' (length=11)
      protected 'created' => 
        object(DateTime)[370]
          public 'date' => string '2015-07-13 11:43:31.000000' (length=26)
          public 'timezone_type' => int 3
          public 'timezone' => string 'Europe/London' (length=13)
      protected 'updated' => 
        object(DateTime)[365]
          public 'date' => string '2015-07-13 11:43:31.000000' (length=26)
          public 'timezone_type' => int 3
          public 'timezone' => string 'Europe/London' (length=13)

但是在我刷新页面后失败了。所以这里有一个奇怪的不一致性

经过一些研究和测试,看起来这个问题与PHP5.4有关,即使我使用PHP5.6()

我尝试使用JSON函数更改序列化过程,现在问题已经解决了。所以现在,
serialize
unserialize
产生了一个问题,但我不知道为什么