Skip to content

AbstractToken serialization fails on php 5.4 #3691

Closed
@blinkseb

Description

@blinkseb

After upgrading to php 5.4, our site backend stopped working. After some digging through the code, the issue is related to an incorrect serialization of AbstractToken roles.

The exception:

PHP Fatal error:  Call to a member function getRole() on a non-object in /vendor/symfony/symfony/src/Symfony/Component/Security/Core/Role/RoleHierarchy.php on line 47

On PHP 5.3, serializing $this->roles

Array ( 
  [0] => Madalynn\Bundle\AndroBundle\Entity\Role Object (
    [id:protected] => 1
    [role:protected] => ROLE_ADMIN
    [description:protected] => The administrator role
    [created:protected] => DateTime Object (
      [date] => 2012-03-24 14:28:58
      [timezone_type] => 3
      [timezone] => UTC )
    [updated:protected] => DateTime Object (
      [date] => 2012-03-24 14:28:58
      [timezone_type] => 3
      [timezone] => UTC ) ) )

gives :

a:1:{i:0;O:39:"Madalynn\Bundle\AndroBundle\Entity\Role":5:{s:5:"*id";i:1;s:7:"*role";s:10:"ROLE_ADMIN";s:14:"*description";s:22:"The administrator role";s:10:"*created";O:8:"DateTime":3:{s:4:"date";s:19:"2012-03-24 14:28:58";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}s:10:"*updated";O:8:"DateTime":3:{s:4:"date";s:19:"2012-03-24 14:28:58";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}}}

On PHP 5.4, the same object serialize to

a:1:{i:0;r:13;}

As a result, $this->roles is unserialized to

array(1) {
  [0] => string(31) "gyokoxjx08owkg0k4wcc08ckowwk04w"
}

Unfortunately, I wasn't able to fix the serialized issue, and a google search does not lead to a simple fix. Hopefully, some Synfony experts will be able to fix this!

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions