PHP Internals News: Episode 72: PHP 8.0 Celebrations! – Derick Rethans

PHP Internals News: Episode 72: PHP 8.0 Celebrations!

In this episode of “PHP Internals News” we’re looking back at all the RFCs that we discussed on this podcast for PHP 8.0. In their own words, the RFC authors explain what these features are, with your host interjecting his own comments on the state of affairs.

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:23

Hi, I’m Derick, and this is PHP internals news, a weekly podcast dedicated to demystifying the development of the PHP language.

Derick Rethans 0:32

This is Episode 72. PHP eight is going to be released today, November 26. In this episode, we look back across the season to find out which new features are in PHP eight dot zero. If I have spoken with the instigator of each of these features, I’m letting them explain what this new feature is. in the first episode of this current year, I spoke with Nikita Popov about weak maps, a feature that builds on top of the weak references that were introduced in PHP seven four. I asked: What’s wrong with the weak references and why do we now need to weak maps.

Nikita Popov 1:10

There’s nothing wrong with references. This is a reminder, what weak references are about, they allow you to reference, an object, without preventing it from being garbage collected. So if the object is unset, then you’re just left with a dangling reference, and if you try to access it you will get acknowledged sort of the object. Now the probably most common use case for any kind of weak data structure is a map or an associative array, where you have objects and want to associate some kind of data with some typical use cases are caches or other memoize data structures. And the reason why it’s important for this to be weak, is that you do not. Well, if you want to cache some data with the object and then nobody else is using that object, you don’t really want to keep around that cache data, because no one is ever going to use it again, and it’s just going to take up memory usage. And this is what the weak map does. So you use objects as keys, use some kind of data as the value. And if the object is no longer used outside this map, then is also removed from the map as well.

Derick Rethans 2:29

A main use case for weak maps will likely be ORMs and related tools. In the next, episode 38, I discussed this trainable interface with Nicolas Grekas from Symfony fame. I asked: Nicolas, could you explain what stringable is.

Nicolas Grekas 2:45

Hello, and stringable is an interface that people could use to declare that they implement some the magic to string method.

Derick Rethans 2:53

That was a short and sweet answer, but a reason for wanting to introduce this new interface was much more complicated, and are also potential issues with breaking backwards compatibility. Nikolas replied to my questioning about that with:

Nicolas Grekas 3:06

That’s another goal of the RFC; the way I’ve designed it is that I think the actual current code should be able to express the type right now using annotations, of course. So, what I mean is that the interface, the proposal, the stringable is very easily polyfilled, so we just create this interface in the global namespace that declare the method and done, so we can do that now, we can improve the typing’s now. And then in the future, we’ll be able to turn that into an actual union type.

Derick Rethans 3:39

I had a chat with Nikita Popov about union types as part of the last season in Episode 33 before PHP seven four was

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

PHP 8.0 brings it all together on Platform.sh – platform.sh

A year in the making, PHP 8.0 has been released to the world! Sporting a plethora of new functionality to offer more power with less code, it’s the most anticipated release of PHP since … well since PHP 7.4 last year. (PHP is exciting, what can I say?) And you can run it today on Platform.sh.
Stronger together As we’ve been covering throughout our series, PHP 8.0 is chock full of new functionality.

Installing PHP extensions without pecl in PHP 8 Docker images – Rob Allen

UPDATE: Since this was published, PR 1087 has been raised and merged with restores pecl to the Docker PHP 8 images.

I discovered recently that pecl is no longer shipped in the PHP Docker images for PHP 8. This appears to be related to the deprecation of --with-pear in PHP core as noted in issue 1029.

Consider this Dockerfile:

FROM php:8.0.0RC5-cli-buster RUN pecl install mongodb && docker-php-ext-enable mongodb

If you build, you’ll discover the pecl cannot be found:

$ docker build -t project1 .
Sending build context to Docker daemon 2.56kB
Step 1/2 : FROM php:8.0.0RC5-cli-buster ---> 8b1f24a39f30
Step 2/2 : RUN pecl install mongodb && docker-php-ext-enable mongodb ---> Running in c013519c47f9
/bin/sh: 1: pecl: not found
The command '/bin/sh -c pecl install mongodb && docker-php-ext-enable mongodb' returned a non-zero code: 127

Fortunately, we can get the source from pecl.php.net ourselves and install it:

FROM php:8.0.0RC5-cli-buster RUN mkdir -p /usr/src/php/ext/mongodb \ && curl -fsSL https://pecl.php.net/get/mongodb | tar xvz -C "/usr/src/php/ext/mongodb" --strip 1 \ && docker-php-ext-install mongodb

As of this writing, it will install version 1.9.0RC1 which is required for PHP 8 anyway, but you can specify the version by adding it to the URL like this: https://pecl.php.net/get/mongodb-1.9.0RC1

docker build now works.

Job done!

PHP Internals News: Episode 71: What didn’t make it into PHP 8.0? – Derick Rethans

PHP Internals News: Episode 71: What didn’t make it into PHP 8.0?

In this episode of “PHP Internals News” we’re looking back at all the RFCs that we discussed on this podcast for PHP 7.4, but did not end up making the cut. In their own words, the RFC authors explain what these features are, with your host interjecting his own comments on the state of affairs.

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:15

Hi, I’m Derick, and this is PHP internals news, a weekly podcast dedicated to demystifying the development of the PHP language. This is Episode 71. At the end of last year, I collected snippets from episodes about all the features that did not make it into PHP seven dot four, and I’m doing the same this time around. So welcome to this year’s ‘Which things were proposed to be included into PHP 8.0, but didn’t make it. In Episode 41, I spoke with Stephen Wade about his two array RFC, a feature you wanted to add to PHP to scratch an itch. In his own words:

Steven Wade 0:52

This is a feature that I’ve, I’ve kind of wish I would have been in the language for years, and talking with a few people who encouraged. It’s kind of like the rule of starting a user group right, if there’s not one and you have the desire, then you’re the person to do it. A few people encouraged to say well why don’t you go out and write it? So I’ve spent the last two years kind of trying to work up the courage or research it enough or make sure I write the RFC the proper way. And then also actually have the time to commit to writing it, and following up with any of the discussions as well.

Steven Wade 1:20

I want to introduce a new magic method the as he said the name of the RFC is the double underscore to array. And so the idea is that you can cast an object, if your class implements this method, just like it would toString; if you cast it manually, to array then that method will be called if it’s implemented, or as, as I said in the RFC, array functions will can can automatically cast that if you’re not using strict types.

Derick Rethans 1:44

I questioned him on potential negative feedback about the RFC, because it suggested to add a new metric method. He answered:

Steven Wade 1:53

Beauty of PHP is in its simplicity. And so, adding more and more interfaces, kind of expands class declarations enforcement’s, and in my opinion can lead to a lot of clutter. So I think PHP is already very magical, and the precedent has been set to add more magic to it with seven four with the introduction of serialize and unserialize magic methods. And so for me it’s just kind of a, it’s a tool. I don’t think that it’s necessarily a bad thing or a good thing it’s just another option for the developer to use

Derick Rethans 2:21

The RFC was not voted on and a feature henceforth did not make it into PHP eight zero.

Derick Rethans 2:27

Operator overloading is a topic that has come up several times over the last 20 years that PHP has been around as even an extension that implements is in the PECL repository. Jan Bøhmer proposed to include user space based operator overloading for PHP eight dot zero. I asked him about a specific use cases:

Jan Böhmer 2:46

Higher mathematical objects like complex numbers vectors, something like tensors, maybe something like the string component of Symfony, you can simply concatenate this string object with a normal string using the concat operator and doesn’t have to use a function to cause this. Most basically this

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

PHP 8.0 feature focus: Named Arguments – platform.sh

Last week’s installment talked about the most contentious new feature of PHP 8.0. In our 10th and final installment, we’ll cover the formerly most contentious feature, one that somehow managed not only to generate little pushback this time around, but to become one of PHP 8.0’s top new features.
In every programming language that has functions (that is, all of them), functions can be called by passing an ordered list of arguments to them as input parameters.

PHP 8.0.0 Release Candidate 5 available for testing – PHP: Hypertext Preprocessor

The PHP team is pleased to announce the eleventh testing release of PHP 8.0.0, Release Candidate 5. This is an extra unplanned release, but we’re not planning to adjust the GA date, however, this may change during the course of the RC cycle. The updated release schedule can, as always, be found on the PHP Wiki page about the PHP 8.0. For source downloads of PHP 8.0.0 Release Candidate 5 please visit the download page.Please carefully test this version and report any issues found in the bug reporting system.Please DO NOT use this version in production, it is an early test version. For more information on the new features and other changes, you can read the NEWS file, or the UPGRADING file for a complete list of upgrading notes. These files can also be found in the release archive. The next release will be the General Availability, planned for Nov 26 2020.The signatures for the release can be found in the manifest or on the QA site.Thank you for helping us make PHP better.

Platform.sh | Journeys Erin Austin + Céline Villet Boongo – platform.sh

Speaking the language of family: how two Platform.sh veterans forged a friendship across the Atlantic Ocean One’s daily commute takes her to the Strasbourg – Saint-Denis stop of the Paris Métro, from where she steps out onto the Boulevard St. Denis, walks a half-block to the Boulevard de Sébastopol, and turns left, passing the sidewalk tables of a trendy brasserie before marching through the elaborately carved stone archway of her office building.

HTTP/2 Push is dead – Evert Pot

One of the hot features that came with HTTP/2 was PUSH frames. The main idea is
that if the server can predict what requests a client might want to make, the
server can preemptively send request/response pairs to the client and warm it’s
cache.

This is a feature I’ve been very interested in for a long time. I feel that it
can be incredibly useful for APIs to invalidate & warm caches, remove the need
for compound requests (which I feel is a hack, although sometimes a
necessary one).

To help advance this idea, I’ve worked on a Internet Draft to let API
clients tell the server what resources they would like to have pushed, I built
a Node.js framework with first-class, deeply integrated Push support, and
added support for Prefer-Push to Ketting.

Unfortunately HTTP/2 push always felt like feature that wasn’t quite there yet.
It’s usefulness was stunted due to Cache-Digest for HTTP/2 being killed
off, and no browser APIs to hook into push events.

The Chrome team has considered removing Push support since at least 2018. The
main reason being that they hadn’t really seen the performance benefit for
pushing static assets. At the time, I tried to defend the feature for
the API use-case.

Yesterday, the Chrome team announced to remove the feature from their HTTP/2 and HTTP/3 protocol implementations.

I’m a little sad that it never got to its full potential, but with this step,
I no longer think it’s worthwhile to invest in this feature. So I’m ceasing
my work on Prefer-Push, and will also remove support from the next major
Ketting version.

On a positive note, I spent a lot of time thinking and working on this, but
it is sometimes nice to just be able to close a chapter, rather than to wait
and let it sizzle out. It’s not an ideal conclusion, but it’s a conclusion
nonetheless.

Current alternatives

Lacking server-driver push, we’re back to many small HTTP request, or compound
requests. This means you either have the N+1 problem, or (in the case of
compound requests) poor integration with HTTP caches. More on this here.

If you’re going the ‘compound request’ route, there is a draft of a similar
header as Prefer-Push; Prefer: transclude, which Ketting also
supports.

A feature that I hoped would work well in the future with Server Push was
server-initiated cache invalidation. We never quite got that. To work around
this, we use Websockets and will keep doing this for the forseeable future.

To reduce general latency of fetching many things, the 103 Early Hints
can help, although this is not supported yet in Chrome, and this is also
only really useful for speeding up delivery of assets like images, css and
Javascript as there’s no way to hook into 1xx responses programmatically in
a browser.