Re: Allow Iterator to be used with current, next, reset, key functions
| From: | Nikita Popov | Date: | Sun, 30 Oct 2016 13:04:31 +0000 |
| Subject: | Re: Allow Iterator to be used with current, next, reset, key functions | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-96650@lists.php.net to get a copy of this message | ||
On Sun, Oct 30, 2016 at 1:48 PM, Alice Wonder <alice@librelamp.com> wrote:
> On 10/30/2016 05:31 AM, Rasmus Schultz wrote:
>
>> On second thought, I agree with that - changing reset() and end()
>> doesn't make sense, because people know them and expect them to work
>> in a certain way. Likely a lot of people would actually continue to
>> use them with intermediary variables the way they do today.
>>
>
> Today?
>
> In PHP 5.6.x I didn't have to use intermediate variables.
>
You did. You simply suppressed the error in PHP 5. In PHP 7 the error
classification changed, so you're no longer suppressing it. See:
https://3v4l.org/2R8Vp
Prior to the PHP 7 release I suggested marking a number of functions
(array_pop/shift, reset, end) as prefer-ref, so they could be used without
warning, see http://markmail.org/message/peefyi46iz2amdbq.
Nothing really
came of it at the time. Just mentioning it here because we can already
avoid the warning right now -- we don't have to drop the IAP first. Both
issues are independent.
However, introducing array_first/last is still better than using reset/end
etc, because these functions can easily trigger an unnecessary array copy,
while array_first/last wouldn't have that problem.
Nikita
>
> Being required to use them was new with PHP 7 and I suspect you will find
> a lot of sites still using pre 7 because they haven't taken the time to
> make sure every app they run works in PHP 7.
>
> All my production servers still run 5.6.x for that reason, I'm only now
> starting to port the apps I can now that it appears the PECL modules I need
> have finally all been updated.
>
> The php apps I am fixing are currently littered with code like this:
>
>
> $SEVENFIX = explode('.', $rs[0]->cover);
> if(end($SEVENFIX) == "whatever") {
> // do stuff
> }
>
> before trying the app in my 7.1.0RCx test servers they worked just fine as
>
> if(end(explode('.', $rs[0]->cover)) == "whatever") {
> // do stuff
> }
>
> So I suppose some people might "continue" to use them with intermediary
> but a lot of code that hasn't been ported to 7 doesn't currently.
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>