Symfony 3 - 注意:unserialize():偏移量为11个字节的错误

I do not understand, I work under Symfony 3 and I just got an error when I want to go to my user administration page:

Notice: unserialize(): Error at offset 11 of 28 bytes

Symfony\Component\Debug\Exception\ ContextErrorException

in vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/ArrayType.php (line 58)

However, before it worked very well, it's very strange. Several other people have already had the same problem but it is never the same cause.

I remember doing a little emptiness in my useless files of my project but I deleted that which was unused, and the commented blocks which I did not use.

If it helps to solve my problem, here is my user.php

Thanks !

EDIT : Ok I'm just very stupid. My User entity inherits from FOSUserBundle. In my database, I had a User who had the role SUPER_ADMIN. Suaf meanwhile, in my code, I deleted this role to leave only the role ADMIN, and I modified myself in the database by removing the "SUPER" too much. I did not think it would make this kind of bug, if anyone can explain to me why, for my culture.

But in any case the problem is still solved!

展开翻译

译文

我不明白,我在Symfony 3下工作,当我想转到我的用户时,我遇到了一个错误 管理页面:</ p>


注意:unserialize():偏移11错误28字节</ p>

Symfony \ Component \ Debug \ Exception / ContextErrorException </ p>
</ blockquote>

  in vendor / doctrine / dbal / lib / Doctrine / DBAL / Types / ArrayType.php(第58行)
</ code> </ pre>

然而,在它运作良好之前,它非常奇怪。 其他几个人已经遇到了同样的问题,但原因从来都不一样。</ p>

我记得在我的项目无用的文件中做了一点空虚,但我删除了那些未使用过的文件, 我没有使用的注释块。</ p>

如果它有助于解决我的问题,这是我的user.php </ p>

谢谢!</ p >

编辑:好的,我只是非常愚蠢。
我的用户实体继承自FOSUserBundle。 在我的数据库中,我有一个具有SUPER_ADMIN角色的用户。 同时,在我的代码中,我删除了这个角色,只留下了ADMIN角色,我通过删除“SUPER”来修改自己在数据库中。 我不认为它会产生这种错误,如果有人能解释为什么,为了我的文化。</ p>

但无论如何问题仍然解决了!</ p> \ n </ div>

1个回答

This happens because roles are stored as a serialized array, like:

a:1:{i:0;s:16:"ROLE_SUPER_ADMIN";}

See this s:16? This means that during unserialization php will take 16 symbols (which are exactly ROLE_SUPER_ADMIN).

So, when you removed SUPER your data became

a:1:{i:0;s:16:"ROLE_ADMIN";}

and s:16 is incorrect, because now you have 10 symbols instead of 16. But php tries to get 16, which causes error.

This leads us to conclusion that editing raw data is not a good idea.

展开翻译

译文



这是因为角色存储为序列化数组,如:</ p>

  a  :1:{i:0; s:16:“ROLE_SUPER_ADMIN”;} 
</ code> </ pre>

请参阅 s:16 </ code>? 这意味着在反序列化期间,php将采用16个符号(正好是 ROLE_SUPER_ADMIN </ code>)。 </ p>

因此,当您删除 SUPER </ code>时,您的数据变为</ p>

  a:1:{i:0;  s:16:“ROLE_ADMIN”;} 
</ code> </ pre>

s:16 </ code> 不正确</ strong>,因为现在你 有 10 </ strong>符号而不是 16 </ strong>。 但是php试图获得16,这会导致错误。</ p>

这使我们得出结论,编辑原始数据不是一个好主意</ strong>。</ p>
</ DIV>

doujiao7325
doujiao7325 哦好的,谢谢你的解释!
7 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!