Eighers Gonna Eight with Sara Golemon and Garbriel Caruso – Voices of the ElePHPant

This episode is sponsored by
Ring Central Developers

The post Eighers Gonna Eight with Sara Golemon and Garbriel Caruso appeared first on Voices of the ElePHPant.

Xdebug Update: July 2020 – Derick Rethans

Xdebug Update: July 2020

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, on the first of each month. You can become a patron to support my work on Xdebug. If you are leading a team or company, then it is also possible to support Xdebug through a subscription.

In July, I worked on Xdebug for about 100 hours, with funding being around 70 hours. I worked mostly on the following things:

Xdebug 3

I spend nearly all of my time improving performance this month, with some help by Michael Voříšek for the profiler feature. Some of this work I have done live through Twitch where I stream (almost) every Monday at 15:30 BST (14:30 UTC/10:30 EDT). Past sessions are available on Vimeo.

In order to find out what can be improved I profiled Xdebug running various workloads. I have selected the following workloads per Xdebug mode

If you have any specific one you’d like to see added, please let me know and I’ll see whether I have CPU cycles for it—running composer update for Pimcore under the C profiler Valgrind takes 2½ hours per run!

In any case, the profiling found out the following possible improvements:

Switch xdebug_sprintf to a new xdebug_str_add_fmt

Xdebug often needs to convert data into a single string, for either writing to file or network, storing function names with arguments in memory, or display purposes. It uses an API xdebug_sprintf which allocates new memory and formats the string according to format specifiers. Often it needs to add this to a xdebug_str buffer that makes up a longer piece of text. After it has added it to that buffer, it frees the allocated memory again.

By creating a new API that can add a formatted string to an xdebug_str buffer, I managed to reduce the amount of memory allocations and frees dramatically. This gave a 10-15% Wall Time performance boost, and a 10-25% reduction in CPU instructions.

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

PHP Internals News: Episode 65: Null safe operator – Derick Rethans

PHP Internals News: Episode 65: Null safe operator

In this episode of “PHP Internals News” I chat with Dan Ackroyd (Twitter, GitHub) about the Null Safe Operator RFC.

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

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 65. Today I’m talking with Dan Ackroyd about an RFC that he’s been working on together with Ilija Tovilo. Hello, Dan, would you please introduce yourself?

Dan Ackroyd 0:37

Hi Derick, my name is Daniel, I’m the maintainer of the imagick extension, and I occasionally help other people with RFCs.

Derick Rethans 0:45

And in this case, you helped out Ilija with the null safe operator RFC.

Dan Ackroyd 0:50

It’s an idea that’s been raised on internals before but has never had a very strong RFC written for it. Ilija did the technical implementation, and I helped him write the words for the RFC to persuade other people that it was a good idea.

Derick Rethans 1:04

Ilija declined to be talking to me.

Dan Ackroyd 1:06

He sounds very wise.

Derick Rethans 1:08

Let’s have a chat about this RFC. What is the null safe operator?

Dan Ackroyd 1:13

Imagine you’ve got a variable that’s either going to be an object or it could be null. The variable is an object, you’re going to want to call a method on it, which obviously if it’s null, then you can’t call a method on it, because it gives an error. Instead, what the null safe operator allows you to do is to handle those two different cases in a single line, rather than having to wrap everything with if statements to handle the possibility that it’s just null. The way it does this is through a thing called short circuiting, so instead of evaluating whole expression. As soon as use the null safe operator, and when the left hand side of the operator is null, everything can get short circuited, or just evaluates to null instead.

Derick Rethans 1:53

So it is a way of being able to call a methods. A null variable that can also represent an object and then not crash out with a fatal error

Dan Ackroyd 2:02

That’s what you want is, if the variable is null, it does nothing. If a variable was the object, it calls method. This one of the cases where there’s only two sensible things to do, having to write code to handle the two individual cases all the time just gets a bit tedious to write the same code all the time.

Derick Rethans 2:20

Especially when you have lots of nested calls I suppose.

Dan Ackroyd 2:25

That’s right. It doesn’t happen too often with code, but sometimes when you’re using somebody else’s API, where you’re getting structured data back like in an in a tree, it’s quite possible that you have the first object that might be null, it’s not null, it’s going to point to another object, and the object could be null so and so so down the tree of the structure of the data. It gets quite tedious, just wrapping each of those possible null variables with a if not null.

Derick Rethans 2:55

The RFC as an interesting ex

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

PHP Internals News: Episode 66: Namespace Token, and Parsing PHP – Derick Rethans

PHP Internals News: Episode 66: Namespace Token, and Parsing PHP

In this episode of “PHP Internals News” I chat with Nikita Popov (Twitter, GitHub, Website) about his Namespaced Names as a Single Token, and Parsing 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:16

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 66. Today I’m talking with Nikita Popov about an RFC that he’s made, called namespace names as token. Hello Nikita, how are you this morning?

Nikita 0:35

I’m fine Derick, how are you?

Derick Rethans 0:38

I’m good as well, it’s really warm here two moments and only getting hotter and so.

Nikita 0:44

Same here. Same here.

Derick Rethans 0:46

Yeah, all over Europe, I suppose. Anyway, let’s get chatting about the RFC otherwise we end up chatting about the weather for the whole 20 minutes. What is the problem that is RFC is trying to solve?

Nikita 0:58

So this RFC tries to solve two problems. One is the original one, and the other one turned up a bit later. So I’ll start with the original one. The problem is that PHP has a fairly large number of different reserved keyword, things like class, like function, like const, and these reserved keywords, cannot be used as identifiers, so you cannot have a class that has the name list. Because list is also a keyword that’s used for array destructuring. We have some relaxed rules in some places, which were introduced in PHP 7.0 I think. For example, you can have a method name, that’s a reserved keyword, so you can have a method called list. Because we can always disambiguate, this versus the like real list keyword. But there are places where you cannot use keywords and one of those is inside namespace names.

So to give a specific example of code that broke, and that was my, my own code. So, I think with PHP 7.4, we introduced the arrow functions with the fn keyword to work around various parsing issues. And I have a library called Iter, which provides various generator based iteration functions. And this library has a namespace Iterfn. So Iter backslash fn. Because it has this fn keyword as part of the name, this library breaks in PHP 7.4. But the thing is that this is not truly unnecessary breakage. Because if we just write Iter backslash fn, there is no real ambiguity there. The only thing this can be is a namespace name, and similarly if you import this namespace then the way you actually call the functions is using something like fn backslash operator. Now once again you have fn directly before a backslash so there is once again no real ambiguity. Where the actual ambiguity comes from is that we don’t treat namespace names as a single unit. Instead, we really do treat them as the separate parts. First one identifier than the backslash, then other identifier, then the backslash, and so on. And this means that our reserved keyword restrictions apply to each individual part. So the whole thing.

The original idea behind this proposal was actually to go quite a bit further. The proposal is that instead of treating all of these segments of the name separately, we treat it as a single unit, as a single token. And that also means that it’s okay to use reserved keywords inside it. As long as like the whole name, taken together is not a reserved keyword. The idea of the RFC was to, like, reduce the impact of additional reserved keywords, introduc

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

Byte-sized functional programming: Filter first – larry@garfieldtech.com

Byte-sized functional programming: Filter first

Often when working with a list, we only want to work with a subset of a list that meets some criteria. All non-zero values, for example, or all users that have a given role. The procedural way to do that is to stick an if statement inside a foreach loop:

<?php
foreach ($list as $value) {
    If (!
meets_criteria($value)) {
        continue;
    }
   
// ...
}
?>

That mixes up the filtering with the iteration, though. It also doesn’t work if we’re using `array_map()`.

Instead, we can make stripping down the list a separate operation called “filter.” PHP offers the array_filter() function for that purpose.

<?php
$criteria
= fn(User $user): bool => $user->hasRole('moderator');

$filtered = array_filter($users, $criteria);
?>

Now we can work with the `$filtered` list, which has only the values we want. That could be a simple foreach loop, or, better, it's now ideally suited for use with array_map().


Want to know more about functional programming and PHP? Read the whole book on the topic: Thinking Functionally in PHP.

Thinking Functionally in PHP

Larry
3 August 2020 - 1:47pm

PHP Internals News: Episode 64: More About Attributes – Derick Rethans

PHP Internals News: Episode 64: More About Attributes

In this episode of “PHP Internals News” I chat with Benjamin Eberlei (Twitter, GitHub, Website) about a few RFCs related to Attributes.

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

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 64. Today I’m talking with Benjamin Eberlei, about a bunch of RFCs related to Attributes. Hello Benjamin, how are you this morning?

Benjamin Eberlei 0:36

I’m fine. I’m very well actually yeah. The weather’s great.

Derick Rethans 0:39

I can see that behind you. Of course, if you listen to this podcast, you can’t see the bright sun behind Benjamin, or behind me, by the way. In any case, we don’t want to talk about the weather today, we want to talk about a bunch of RFCs related to attributes. We’ll start with one of the RFCs that Benjamin proposed or actually, one of them that he has proposed and one of them that he’s put into discussion. The first one is called attribute amendments.

Benjamin Eberlei 1:05

Yes.

Derick Rethans 1:06

What is attribute amendments about?

Benjamin Eberlei 1:08

So the initial attributes RFC, and we talked about this a few months ago was accepted, and there were a few things that we didn’t add because it was already a very large RFC, and the feature itself was already quite big. Seems to be that there’s more sort of an appetite to go step by step and put additional things, in additional RFCs. So we had for, for I think about three or four different topics that we wanted to talk about, and maybe amend to the original RFC. And this was sort of a grouping of all those four things that I wanted to propose and change and Martin my co author of the RFC and I worked on them and proposed them.

Derick Rethans 1:55

What are the four things that your new RFC was proposing?

Benjamin Eberlei 1:59

Yes, so the first one was renaming Attribute class. So, the class that is used to mark an attribute from PHP attributes to just attribute. I guess we go into detail in a few seconds but I just list them. The second one is an alternative syntax to group attributes and you’re safe a little bit on the characters to type and allowed to group them. And the third was a way to validate which declarations, an attribute is allowed to be set on, and the force was a way to configure if an attribute is allowed to be declared once or multiple times on one declaration.

Derick Rethans 2:45

Okay, so let’s start with the first one which is renaming the class to Attribute.

Benjamin Eberlei 2:51

Yeah, so in the initial RFC, there was already a lot of discussion about how should this attribute class be caught. Around that time that PhpToken RFC was also accepted, and so I sort of chose this out of a compromise to use PhpAttribute, because it is guaranteed to be a unique name that nobody would ever have used before. There’s also, there was also a lot of talk about putting an RFC, to vote, about namespacing in PHP, so namespacing internal classes and everything. So I wanted to keep this open at the at the time and not make it a contentious decision. After the Attributes RFC was accepted, then namespace

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