![]() And that's to unwrap or to break the reference after the loop. What are you proposing to change with this RFC? Nikita Popov 2:57 The change is pretty simple. But I'm pretty sure I have some point in the past. Derick Rethans 2:47 I think it is one I have used in the past, it's probably not how I would do it now. This is a use case we would break with the proposed RFC. But I'm sure people have used in here there. I don't think this is a particularly common use case. ![]() Derick Rethans 2:24 Is this not something that people actually use for some useful reasons? Nikita Popov 2:28 As mentioned before, technically, you could use it to get a reference to the last element and then modify the last element outside the foreach loop. It's the last one that's been assigned to? Nikita Popov 2:22 Yeah, that's, that's true. Derick Rethans 2:15 Okay, just to clarify, it isn't necessarily the last element in the foreach loop. So if you now have a second foreach loop, using the same variable, that's actually not just modifying that variable, but it's also always modifying the last element of the array. ![]() ![]() If the last element now is a reference, so if you have a reference to the last element, then you're write into that variable is also going to modify the last element of the array. So you will just have like reference to the last element of the array, might even be useful for some cases, you know, before we added the array, I think, array_key_last function. And usually, that won't make much of a difference. So if you have a foreach array as value, then the value variable is going to stay alive, even after the foreach loop. Derick Rethans 1:27 Can you quickly explain the scoping or rather the lack of it, I suppose? Nikita Popov 1:31 Yeah, it's really the lack of PHP really only has function scoping. So I think it's worth explaining what's going on there. If you're not familiar with how references in PHP work and scoping in PHP works. The result of that is that your last two array elements are going to be the same, which is kind of unexpected. So foreach array as value by reference, and then you do a second loop after that, foreach array as value at the same it's by value. It's like a classic example, you have a foreach loop by reference. I think it's a relatively well known problem for the more experienced PHP programmers. Derick Rethans 0:43 So what is the problem that is RFC is going to solve? Nikita Popov 0:46 Well, it's really a very minor thing. Nikita Popov 0:41 Yes, at the time before that. Derick Rethans 0:38 So no changes compared to the last time. I'm Nikita and I work at JetBrains on PHP core development. Nikita, would you please introduce yourself? Nikita Popov 0:33 Hi, Derick. Today I'm talking with Nikita Popov about the unwrap reference after foreach RFC that he's proposing. Welcome to PHP internals news, the podcast dedicated to explaining the latest developments in the PHP language. Transcript Derick Rethans 0:14 Hi, I'm Derick. In this episode of "PHP Internals News" I chat with Nikita Popov ( Twitter, GitHub, Website) about the "First Class Callable Syntax" RFC. ![]() Thursday August 26th, 2021 - 09:22 BST Description ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |