문제

I'm having this problem when I am trying to serialize my class I get the exception

Serialization of 'SimpleXMLElement' is not allowed.

I don't get the error. I am not even using the xml features of PHP.. What does this error mean ?

The code:

$test = new \My\Name\Space\MyClass();

die(serialize($test));
도움이 되었습니까?

해결책

You have a SimpleXmlElement in the object graph of the \My\Name\Space\MyClass instance but it cannot be serialized. Add the magic __sleep method to influence which properties get serialized and which are ignored or implement the Serializable interface

다른 팁

I just made an array of all my attributes in the class and serialized that one, when I get the array back out of the session I unserialize it and load it back in.

I made 2 extra methods in the class. 1 to get the array, and the other to load the array.

I didn't found where the SimpleXmlElement is used in Symfony 2.

And now it works.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top