PHP Internals News: Episode 75: Globals, and Phasing Out Serializable
PHP Internals News: Episode 75: Globals, and Phasing Out Serializable
In this episode of "PHP Internals News" I chat with Nikita Popov (Twitter, GitHub, Website) about two RFCs: Restrict Globals Usage, and Phase Out Serializable.
The RSS feed for this podcast is https://derickrethans.nl/feed-phpinternalsnews.xml, you can download this episode's MP3 file, and it's available on Spotify and iTunes. There is a dedicated website: https://phpinternals.news
Transcript
- Derick Rethans 0:14
-
Hi I'm Derick. Welcome to PHP internals news, a podcast dedicated to explain the latest developments in the PHP language. This is Episode 75. In this episode, I'm talking with Nikita Popov about a few RFCs that he has been working on over the past few months. Nikita, would you please introduce yourself?
- Nikita Popov 0:34
-
Hi, I'm Nikita, I work at JetBrains on PHP core development and as such I get to occasionally, write PHP proposals RFCs and then talk with Derick about them.
- Derick Rethans 0:47
-
The main idea behind you working on RFCs is that PHP gets new features not, you end up talking to me.
- Nikita Popov 0:53
-
I mean that's a side benefit,
- Derick Rethans 0:55
-
In any case we have a few to go this time. The first RFC is titled phasing out Serializable, it's a fairly small RFC. What is it about?
- Nikita Popov 1:04
-
That finishes up a bit of work from PHP 7.4, where we introduced a new serialization mechanism, actually the third one, we have. So we have a bit too many of them, and this removes the most problematic one.
- Derick Rethans 1:19
-
Which three Serializable methods or ways of doing things currently exist?
- Nikita Popov 1:24
-
The first one, which doesn't really count is just what you get if you don't do anything, so just all the Object Properties get serialized, and also unserialized, and then we have a number of hooks, you can use to modify that. The first pair is sleep and wake up. Sleep specifies which properties you want to serialize so you can filter out some of them, and wake up allows you to run some code, after unserialization, so you can do some kind of fix up afterwards.
- Derick Rethans 1:52
-
From what I remember, if you use unserialize, where does the wake up the constructor doesn't get called?
- Nikita Popov 1:59
-
During unserialization the constructor, never gets called.
- Derick Rethans 2:03
-
So wake up a sort of the static factory methods to re rehydrate the objects.
- Nikita Popov 2:08
-
Exactly.
- Derick Rethans 2:08
-
So that's number one,
- Nikita Popov 2:10
-
Then number two is the Serializable interface, which gives you more control. Namely, you have to actually like return the serialized representation of your object. How it looks like is completely unspecified, you could return whatever you want, though, in practice, what people actually do is to recursively call serialize. And then on the other side when unserializing you usually do the same so you call unserialize on the stream you receive, and then populate your properties based on that. The problem with this mechanism is exactly this recursive serialization call, because it has to share state, with the main serialization. And the
Truncated by Planet PHP, read more at the original (another 22227 bytes)