[wp-trac] [WordPress Trac] #3394: Possible bug in update_option()

WordPress Trac wp-trac at lists.automattic.com
Sun Nov 26 20:54:05 GMT 2006


#3394: Possible bug in update_option()
-----------------------+----------------------------------------------------
 Reporter:  roscohead  |       Owner:  anonymous
     Type:  defect     |      Status:  new      
 Priority:  normal     |   Milestone:           
Component:  General    |     Version:           
 Severity:  normal     |    Keywords:           
-----------------------+----------------------------------------------------
 I posted this on the forum, and someone kindly pointed me here :)

 I think I've hit a bug in the update_option() function. The problem occurs
 when the $newvalue is an array containing arrays - it checks
 {{{
         // If the new and old values are the same, no need to update.
         $oldvalue = get_option($option_name);
         if ( $newvalue == $oldvalue ) {
                 return false;
         }
 }}}
 to see if the value has changed. However this behaves incorrectly when the
 only change is in the order of elements of the sub-array, the comparison
 returns true, so the setting is never updated.

 My workaround is to do a comparison on the serialized versions instead:
 {{{
         // If the new and old values are the same, no need to update.
         $oldvalue = get_option($option_name);
         if ( maybe_serialize($newvalue) == maybe_serialize($oldvalue) ) {
                 return false;
         }
 }}}
 This seems to work, and doesn't seem to break anything, but it has only
 been minimally tested. If there's a better way to fix the problem, feel
 free to ignore my suggested fix :)

 ROSCO

-- 
Ticket URL: <http://trac.wordpress.org/ticket/3394>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list