PHP Internals News: Episode 76: Globals, and Phasing Out Serializable – Derick Rethans

PHP Internals News: Episode 76: Globals, and Phasing Out Serializable

In this episode of “PHP Internals News” I chat with Nikita Popov (Twitter, GitHub, Website) about two RFCs: Deprecate passing null to non-nullable arguments of internal functions, and Deprecate passing null to non-nullable arguments of internal functions.

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 76. In this episode, I’m talking with Nikita Popov about a few more 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 on PHP core development on behalf of JetBrains.

Derick Rethans 0:39

In the last few PHP releases PHP is handling of types with regards to internal functions and user land functions, has been getting closer and closer, especially with types now. But there’s still one case where type mismatches behave differently between internal and user land functions. What is this outstanding difference?

Nikita Popov 0:59

Since PHP 8.0 on the remaining difference is the handling of now. So PHP 7.0 introduced scalar types for user functions. But scalar types already existed for internal functions at that time. Unfortunately, or maybe like pragmatically, we ended up with slightly different behaviour in both cases. The difference is that user functions, don’t accept null, unless you explicitly allow it using nullable type or using a null default value. So this is the case for all user types, regardless of where or how they occur as parameter types, return values, property types, and independent if it’s an array type or integer type. For internal functions, there is this one exception where if you have a scalar type like Boolean, integer, float, or a string, and you’re not using strict types, then these arguments also accept null values silently right now. So if you have a string argument and you pass null to it, then it will simply be converted into an empty string, or for integers into zero value. At least I assume that the reason why we’re here is that the internal function behaviour existed for a long time, and the use of that behaviour was chosen to be consistent with the general behaviour of other types at the time. If you have an array type, it also doesn’t accept now and just convert it to an empty array or something silly like that. So now we are left with this inconsistency.

Derick Rethans 2:31

Is it also not possible for extensions to check whether null was passed, and then do a different behaviour like picking a default value?

Nikita Popov 2:40

That’s right, but that’s a different case. The one I’m talking about is where you have a type like string, while the one you have in mind is where you effectively have a type like string or null.

Derick Rethans 2:51

Okay.

Nikita Popov 2:52

In that case, of course, accepting null is perfectly fine.

Derick Rethans 2:56

Even though it might actually end up being different defaults.

Nikita Popov 3:01

Yeah. Nowadays we would prefer to instead, actually specify a default value. Instead of using nu

Truncated by Planet PHP, read more at the original (another 13729 bytes)

PHP Internals News: Episode 75: Globals, and Phasing Out Serializable – Derick Rethans

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)

Xdebug Update: January 2021 – Derick Rethans

Xdebug Update: January 2021

Another monthly update where I explain what happened with Xdebug development in this past month. These will be published on the first Tuesday after the 5th of each month.

Patreon and GitHub supporters will get it earlier, around the first of each month.

You can become a patron or support me through GitHub Sponsors. I am currently 94% towards my $1,000 per month goal.

If you are leading a team or company, then it is also possible to support Xdebug through a subscription.

In January, I worked on Xdebug for about 60 hours, with funding being around 35 hours. I worked mostly on the following things:

Releases

The start of the month saw the release of Xdebug 3.0.2 which addresses further issues that are present in Xdebug 3.0. Xdebug 3.0.2 mainly addresses issues related to triggering features in Xdebug through Xdebug’s new modes, and a few issues related to code coverage were fixed too. Expect another bug fix release in February, as I am intending to make one release per month.

Now that the GitHub repository of the VS Code Plugin has been moved to the Xdebug organisation, there is going to be progress here too.

DBGp Client and DBGp Proxy

I have had some expert reviews of the Go code for DBGp Client and DBGp Proxy, by JetBrains developers working on their GoLand IDE. Once I have reviewed and integrated their comments I am intending to release the source code of these two tools under an open source license.

Documentation

I spent some time adding anchors throughout the documentation to make it easier to link to specific sections. The upgrade guide now also has a Japanese translation. Xdebug.org’s code has been updated to allow for translations of the documentation, although I do not have any plans to translate the rest of it at the moment. The main issue with having translations of the documentation that the translations also need updating when the original in English changes.

As part of Xdebug’s documentation efforts I created another video in my series on Xdebug 3. This new video explains Xdebug 3’s diagnostics features to help finding issues with Xdebug’s configuration and settings.

The next video that I am going to release will deal with how to trigger Xdebug’s features, such as single step debugging, profiling, and tracing.

Xdebug Cloud

The Xdebug Cloud now has a design, created by Simon Collison. With the design in place, I am currently putting the dots on the i’s related to signing up and billing. I expect to launch Xdebug Cloud for beta customers during this month.

If you want to be kept up to date with Xdebug Cloud, please sign up to the mailinglist, which I will use to send out an update not more than once a month.

PHP Internals News: Episode 74: Fibers – Derick Rethans

PHP Internals News: Episode 74: Fibers

In this episode of “PHP Internals News” I talk with Aaron Piotrowski (Twitter, Website, GitHub) about an RFC that he is proposing to add Fibers to PHP.

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, the podcast dedicated to explaining the latest developments in the PHP language. This is Episode 74. Today I’m talking with Aaron Piotrowski about a Fiber RFC, that he’s working on together with Nicolas Keller. Aaron, would you please introduce yourself.

Aaron Piotrowski 0:33

Hi everyone I’m Aaron Piotrowski, I started programming with PHP back in 1998 with PHP three, so I’ve just dated myself there but, but I’ve worked with a lot of different languages over the last few decades but PHP is always continually remaining, one of my favourite and I’m always drawn back to it. I’ve gotten a lot more involved with the PHP projects since PHP seven. The Fiber RFC is my first major contribution I have attempted though. In the past I did the RFC for the throwable exception hierarchy. And the Iterable pseudo type in PHP 7.1.

Derick Rethans 1:12

Yeah, these things are both before I started doing the podcast so hence we haven’t spoken yet, at least on here. We’ve actually met at some point in the past. I’ve had a read through the Fiber RFC this morning, but I’m still fairly baffled. Could you perhaps explain in short what Fibers are where the idea comes from. And what’s your specific interest is in adding them to PHP?

Aaron Piotrowski 1:35

A few other languages already have Fibers like Ruby, and they’re sort of similar to threads in that they contain a separate call stack, and a separate memory stack, but they differ from threads in that they exist only within a single process, and that they have to be switched to cooperatively by that process rather than actively by the OS like threads. So sometimes they’re called Green threads, and the generators that are in PHP already are actually somewhat similar to Fibers; but generators differ in that they’re stack less. And so what that means is that generator function can only be interrupted at one layer. Whereas a Fiber can be interrupted anywhere in the call stack. So like it’d be imagine if you had a generator where yield could be very deep in a function call. Rather than at the top level. Like, how generators can be used to make interruptible functions, Fibers can also be used to create similarly interruptible functions, but with again without having to know exactly when it’s going to be interrupted not at the top level but at any point in the call stack. And so the main motivation behind wanting to add this feature is to make asynchronous programming in PHP much easier and eliminate the distinction that usually exists between async code that has used promises and synchronous code that we’re all used to.

Derick Rethans 3:09

So what specifically are you proposing to ask to PHP here then?

Aaron Piotrowski 3:12

Specifically I’m looking at adding a low level Fiber API, that’s really aimed specifically at async framework authors to create their own more opinionated API’s on top of that low level API. So adds just a couple of classes: Fiber, and a FiberScheduler on within a couple of exception classes and reflection classes for inspecting Fibers. When a Fiber is suspended to the execution switch is to FiberScheduler, which is then a special Fiber, that’s able to start and resume, regular user Fibers. So a Fiber scheduler is general

Truncated by Planet PHP, read more at the original (another 18886 bytes)

Ketting support for deprecation warnings – Evert Pot

Ketting is the generic REST client for Javascript.

Version 7 is currently in beta, and will have support for Deprecation
and Sunset headers as well as deprecated links.

Deprecating Endpoints/Resources

There’s currently work done on a new internet standard:
draft-cedik-deprecation-header, a.k.a.:
“The Deprecation HTTP Header Field”.

The way this works is that the server may emit a header such as one of these:

HTTP/1.1 200 OK
Deprecation: Mon, 1 Nov 2021 00:00:00 GMT
Deprecation: true

If a server emits these, it tells the client that the endpoint should no
longer be used, or will be removed at a future date.

If specified, Ketting will now send warnings to the console via console.warn,
making it easier to spot reliance on deprecated endpoints.

The draft also defines the following additional headers:

HTTP/1.1 200 OK
Sunset: Wed, 1 Dec 2021 00:00:00 GMT
Link: </docs/update-2021>; rel="deprecation"

These headers allow a server to tell a client when the endpoint will stop
responding, and point to additional information about the depreciation.

If either of these are specified, Ketting will provide this information in
the console.

Aside from entire resources being deprecated, individual links may also get
deprecated. Given a HAL document, this may look like the following:

{ "_links": { "next": { "href": "/next-page", "hints": { "status": "deprecated" } } }
}

The format for ‘hints’ is documented in draft-nottingham-link-hint.

When you follow the next link with Ketting, Ketting will now also emit
a console warning.

// Emits warning
const nextResource = await resource.follow('next')

Want to give this a shot? Update to the latest Ketting with:

npm i ketting@beta