In the #3 patch, The condition should be.
if (!empty($key_value) && $...