-
Notifications
You must be signed in to change notification settings - Fork 7.8k
If the first numeric index of an array is negative let the next one stay negative #2383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Something that is documented, and that works the same in every released version of PHP (and hhvm) can't really be described as unexpected, or buggy. It's surprising at the most ... I think this needs an RFC to resolve it, so I'm going to label it as such ... at the very least it requires an internals discussion. |
Agreed. I'll start a discussion on internals later today. Thanks for the feedback! |
sorry guys, I didn't see this PR before I sent my one, but I have alternative approach to fix this. |
I don't think it's a thing that needs fixing (although it is wtfaf). At most, I'd say deprecate this method and introduce a new one, but even that feels heavy handed given how positively ancient this function is. |
@sgolemon, thanks for the feedback. If you check the implementation, you'll see that this change wouldn't be limited to the array_fill function but to all arrays where the first key is negative. So, in the scope of this implementation, deprecating a function/introducing a new one wouldn't really make sense. |
@pmmaga I am wondering how it will influence existing code which relies on previous version of array indexes? |
@andrewnester, yes, it would introduce a BC break in those cases. |
Looks like the latest changes broke the build completely... |
It did indeed. I didn't have the time to fix this today so I added the [WIP] to the title until I get it right again. |
2dc15a3
to
b55489f
Compare
Ok, I've managed to fix the issues and it's all green now. |
This definitely should not target PHP 7.2 as it breaks backward compatibility. |
'Documented but unexpected' doesn't make any sense to me? Changing documented behaviour is a clear BC break so this should target |
I'd rather see an extra param to |
see https://wiki.php.net/rfc/releaseprocess |
I find the current behaviour of |
b55489f
to
dec8f3a
Compare
I have updated the RFC to target 8.0 and updated this PR to throw a |
dec8f3a
to
34bb2da
Compare
34bb2da
to
0250615
Compare
Following the vote on https://wiki.php.net/rfc/negative_array_index and given that the deprecation notice was rejected, I'm closing this PR. |
For reference: this was implemented in PHP 8.0 as #3772. |
The current behavior of
array_fill(-10, 3, true)
- although documented - is unexpected.This same behavior can also be seen in array declarations with an explicit negative index.
IMHO, this sits in a limbo between a bugfix and a language change. Or, in other words, it seems to me that the only reason why this would not be a bug would be the fact that it is documented.
Let me know what you think.
Link to the RFC: https://wiki.php.net/rfc/negative_array_index