 Hey everybody, it's Brian and welcome to the 41st Lamps Tutorial. Today we're going to discuss serialization. So what is serialization? Serialization is the art, if you will, of saving an instance of a class to the hard drive and then reading it back from memory. Why did I just say? That's right. We're going to take an instance of the class. Let's actually make one now. Make a new test. Then we're going to set the property here of name. I'm going to say my name is, not if, is Brian. Now we're going to save to the disk. We do this by making yet another variable and we'll call it serialize. And we're going to serialize the instance of that class. Now notice I'm saying the instance. We're not saving the class to the disk. The class has already been saved to the disk in this file. What we're saving is the instance. In other words, every property that's set in here will also be saved. So we're going to serialize it into another variable. And then we're just going to file, put contents. And we're going to say serialclass.txt. In the real world, don't do txt because some nosy sysad men might go in and start modifying the contents of the class. Just doing it for sake of instruction here. So we're going to echo out, save to disk. Alright, so it's been saved to the hard drive. Let's go out and find it here. This is where you need the Jeopardy music. These virtual machines are so slow on my computer. But then again, I am really used to like a server environment where they're just lightning fast. Oh, where is it? Serialclass.txt. Here we go. So open this up in a g-editor notepad, whatever you got. And you see here is the class in all its glory. And there's some weird things going on here where you can see the name of the class. It's called Jeopardy. And then you can see the actual value. So that's kind of the structure that it saves it in. Totally incomprehensible to the mere mortal. But that's what it's doing is it's just saving it to the hard drive. Let's go out here. And now we're going to load it back into RAM. And we do this by saying, let's make a different one, file, get contents. We just need the same file name here. Any minute now my laundry is going to be done. I actually wasn't feeling very well today, so I called in sick to work. I'm just feeling blah. All right, so we're loading the contents from the file. Now we need to deserialize it or unserialize it. So we're just going to make anyone call B equal. You guessed it, unserialize. And then there we go. So we're going to just echo. My name is Brian. So let's review. We made a class. We made an instance of that class and set some properties. We save it out to the hard drive. We're just echoing out, save to disk. And then we're going to load it back into memory, meaning we're going to actually get the contents of that file, put it into a variable, and then unserialize the variable into yet another variable. And then we have a working instance of that class, exactly in the same state that it was. That's all for this tutorial. I hope you found this educational and entertaining. Thank you for watching.