-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Remove unnecessary isset()
checks and fix key exists checks
#19914
Remove unnecessary isset()
checks and fix key exists checks
#19914
Conversation
PR Summary
|
…to deal with float keys (even when their value is `null`)
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #19914 +/- ##
==========================================
- Coverage 48.90% 48.89% -0.01%
==========================================
Files 445 445
Lines 42806 42790 -16
==========================================
- Hits 20935 20923 -12
+ Misses 21871 21867 -4
☔ View full report in Codecov by Sentry. |
… and `::remove()` functions when the key is a float and the value is `null`)
isset()
checksisset()
checks and fix key exists checks
Shouldn't you first remove SUPPORT for PHP5 before removing optimizations for it? Unless it goes into Yii 2.2 but it does not say so here anywhere. |
This code still works for PHP <7.3, just slightly slower, so this is not really a BC break. According to https://packagist.org/packages/yiisoft/yii2/php-stats these are less than 10% of installs, so improving performance for 90% of users at the cost of decreasing performance 10% users, still makes sense (especially that if you care about performance, you would not stuck of PHP 7.2 or lower). |
It's not, but it should be (see below).
Except you never measured the amount of performance improvement for 10% of users (ain't you were quick to dismiss MY performance claims as "negligible" only yesterday in #19788?) but you surely decreased the performance notably (if it wasn't notable those optimizations wouldn't exist in the first place) for the 10% of users you consider to be SUPPORTED. If you don't want to drop PHP5 support in Yii2 you must put this PR change in Yii2.2 because it is detrimental for users on PHP5 you still claim to support and the users of PHP7+ will have no problem with removed support for PHP5 and so will be able to switch to Yii2.2 without problems. This way both 90% AND 10% of supported users win. |
This was always a micro-optimization and thus it is hard to benchmark this (if I have I think that we should not aim with such micro-optimization to old and unsupported versions of PHP, especially if it decreases performance of recent versions used by 90% of users. That is actually a micro-deoptimization. :P |
@rob006 |
For example in this you are concerned of the performance degradation of old PHP version. Your option is "Support it like the rest supported or drop support altogether". Rob have the same view but only he thinks that someone who clings to old 5.6 should have some weight on his own shoulder, as practically there is no any serious reason not to upgrade to 7.x (correct me if am wrong) In such discussion both are useful argument and the question really is, how much do we want support parity to be in those old PHP versions. My opinion is we should really ignore some issues like this, with big note on upgrade notes/change log that if you are using PHP5.6 for example, above change will affect you this way. And suggest upgrade to 7.x Subtle deprecation of the framework support for 5.6 if you wish before actual support is dropped. That is one example of approach we can take. But honestly rather than you guys debate two valid use cases viewed differently, I would suggest you propose couple of solutions. Then it will be easier to discuss and pick one of those solutions. So what do you propose we do with this @PowerGamer1? I see Rob have proposed this one loud and clear
|
Nowhere in this PR here is anything that "drops" support for PHP v5. It actually increases compatibility for all version < 8.1. |
If you want to keep your claim that you still SUPPORT PHP5 then have a decency to do such support properly or at least NOT remove ALREADY EXISTING optimizations for PHP5. Otherwise get rid of that support ENTIRELY and then feel free to improve the code without being limited by obligations and constraints the claim of "SUPPORT" comes with. My personal preference is dropping support for PHP5. Either you do it in Yii2 or Yii2.2 is up to you. But that commit should only go into the branch without PHP5 support.
That is exactly the problem - you are not dropping it, but you should.
Instead of making optimizations for 100% of user base by dropping support for PHP5 which is more than very long overdue. P.S. Please do whatever you want and don't reply to me in this topic any longer. You have your opinion and I have mine, lets leave it at that. |
Thanks. |
Until PHP version 7.3 the
array_key_exists()
function was relatively slow. A workaround for it was to first do anisset()
check.Since PHP 7.4 the
array_key_exists()
is faster thanisset()
, let alone doing both checks.This PR removes the now unnecessary
isset()
checks and fixes a bug where floats are passed as key.Originally described in #11549 PHP casts float keys to integer, however, the
isset()
function will returnfalse
in case the key's value isnull
resulting in a float being passed toarray_key_exists()
which causes the exception "array_key_exists(): The first argument should be either a string or an integer".This is solved by casting the
$key
toint
in case it's a float.