MapCacheLRU performs various type checks, e.g. in has():
if ( !is_int( $key ) && !is_string( $key ) ) { throw new UnexpectedValueException( __METHOD__ . ': invalid key; must be string or integer.' ); }
While these are not slow on their own, they might become a problem if this method is called many times. Looking at a sample request, MapCacheLRU::has() is called 200k times, which clearly makes it hot. Also, although it might be possible to decrease the call count by refactoring the callers, MapCacheLRU is a cache, which means it should be as quick as possible, or it might be quicker to recompute whatever value is being cached.
It's also not 100% clear what the intent of this code is. Should it guard against types that are not valid array keys? This would be unnecessary, as PHP checks it upon reading the offset. Or, it might be guarding against the few edge cases with array keys:
- Booleans, floats, and strings that are the canonical representation of an integer will be cast to integers
- Null will be cast to the empty string
If this is the case, and we don't trust the caller to validate the key, the only BC solution is (I think) to use PHP 8's union types, which is obviously far far away.
The same is also true for setField() and hasField().