Make WordPress Core

Opened 9 years ago

Last modified 6 weeks ago

#32848 accepted defect (bug)

Null values for Update Options does not reset in $all_options

Reported by: mikengarrett's profile MikeNGarrett Owned by: pbearne's profile pbearne
Milestone: Priority: normal
Severity: normal Version: 4.2.2
Component: Cache API Keywords: has-patch needs-unit-tests bulk-reopened
Focuses: performance Cc:


This is a fun, extremely niche case.

We were using the Settings API to save out options for a plugin when we came across a really frustrating scenario. Half the time our setting was returning values that were not accurate to the setting that was stored in the database and in cache.

Come to find, the value being returned from wp_load_alloptions was incorrect while every other instance was correct. In our case, these values were in the database, memcache, and the single value in wp-object-cache.

On line 319 of option.php, we're using isset to check the value in the array. This returns false if the value is NULL. This leads to all kinds of sadness.

I would propose we instead use array_key_exists here to ensure we're getting true if the key is present in the array at all.

Attachments (2)

32848.diff (510 bytes) - added by MikeNGarrett 9 years ago.
Patch #1
32848.2.diff (5.1 KB) - added by MikeNGarrett 9 years ago.
Patch 2 - replace all isset in option.php

Download all attachments as: .zip

Change History (9)

9 years ago

Patch #1

This ticket was mentioned in Slack in #core by mikengarrett. View the logs.

9 years ago

#2 @MikeNGarrett
9 years ago

Co-contributor: @tndavide, @jipmoors

Last edited 9 years ago by MikeNGarrett (previous) (diff)

#3 @MikeNGarrett
9 years ago

  • Keywords has-patch needs-unit-tests added

I ran back through and realized there were quite a few places here that are using isset for assessing array keys existence. Here's a patch to switch all isset to array_key_exists. Next step, let's create some unit tests.

9 years ago

Patch 2 - replace all isset in option.php

#6 @MikeNGarrett
5 years ago

  • Keywords bulk-reopened added

This is still present, but it's a very narrow and uncommon case. I would be ok closing this.

#7 @pbearne
7 weeks ago

  • Owner set to pbearne
  • Status changed from new to accepted

isset is faster than array_key_exist

we could do both which is only a little slower



This ticket was mentioned in Slack in #core-performance by pbearne. View the logs.

7 weeks ago

#9 @MikeNGarrett
6 weeks ago

It's been a minute, so let me wrap my head around this.

The original issue is that in the case of $options = array('test' => null); that isset($options['test']) returns false, leading to differences in the structure of the options array.

I just checked out 6.5.2 ( and it looks like this issue still exists.

I think adding a secondary check for array_key_exists() after isset() would work wonderfully without slowing down execution in most circumstances.

Note: See TracTickets for help on using tickets.