[wp-trac] [WordPress Trac] #23381: update_option() stores unserialized value in object cache
WordPress Trac
noreply at wordpress.org
Mon Feb 4 15:03:54 UTC 2013
#23381: update_option() stores unserialized value in object cache
-----------------------------+--------------------------
Reporter: rmccue | Type: defect (bug)
Status: new | Priority: normal
Milestone: Awaiting Review | Component: Cache
Version: | Severity: normal
Keywords: has-patch |
-----------------------------+--------------------------
`update_option()` and `add_option()` have inconsistent behaviour when
storing items in the cache. `add_option()` stores the serialized version,
whereas `update_option()` stores the raw data. When using APC for object
caching, this can result in objects being loaded in `wp_load_alloptions()`
before the class for it is defined in a plugin.
In `update_option()` (storing raw data):
{{{
$_newvalue = $newvalue;
$newvalue = maybe_serialize( $newvalue );
// ...
$alloptions[$option] = $_newvalue;
wp_cache_set( 'alloptions', $alloptions, 'options'
);
}
}}}
Whereas in `add_option()` (storing serialized data):
{{{
$_value = $value;
$value = maybe_serialize( $value );
// ...
$alloptions[$option] = $value;
wp_cache_set( 'alloptions', $alloptions, 'options'
);
}}}
Example plugin included, breaks horribly when using the APC cache, as that
doesn't enforce serialization internally. This only occurs when using
`update_option()` on an existing option.
Looks like this was introduced in r13673.
= Steps to reproduce =
1. Install markjaquith's APC object caching plugin
2. Activate my plugin. Each refresh will append an object to the array
3. Note output is:
{{{
array(0) {
}
}}}
4. Refresh. Note new output is:
{{{
array(1) {
[0]=>
object(rmccue_Test_Object)#275 (0) {
}
}
}}}
5. Refresh again. Output should be:
{{{
array(2) {
[0]=>
object(__PHP_Incomplete_Class)#5 (1) {
["__PHP_Incomplete_Class_Name"]=>
string(18) "rmccue_Test_Object"
}
[1]=>
object(__PHP_Incomplete_Class)#6 (1) {
["__PHP_Incomplete_Class_Name"]=>
string(18) "rmccue_Test_Object"
}
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23381>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list