How does object serialize/unserialize work?

前端 未结 3 1705
故里飘歌
故里飘歌 2021-01-05 07:56

I was reading about serialize/unserialize concepts of PHP. I was wondering how they are stored in the filesystem/db. I guess it is in the binary format. However, I wonder ho

3条回答
  •  臣服心动
    2021-01-05 08:25

    PHP can know what to do at line#2 but how it knows what to do at line#5 which is a unserialized object? does it save the code as well?

    Yes, serialize() will save the information about the class which this object is an instance of, along with its state, so when you unserialize, you get an instance of that class, which in this case is ClassName.

提交回复
热议问题