Boolean and integer strings are strings after serialization

I am using WordPress update_post_meta to save an array like

$obj = array(
    'array' => array(1, 'zwei', !!3),
    'string' => 'abc',
    'bool' => true,
    'bool2' => false,
    'integer' => 1,
    'integer2' => 17
);

update_post_meta($post_ID, 'my-key', $obj);

however, if I check the source field, I get

a:6:{s:5:"array";a:3:{i:0;i:1;i:1;s:4:"zwei";i:2;s:1:"1";}s:6:"string";s:3:"abc";s:4:"bool";s:1:"1";s:5:"bool2";s:1:"0";s:7:"integer";i:1;s:8:"integer2";i:17;}

while he should be

a:6:{s:5:"array";a:3:{i:0;i:1;i:1;s:4:"zwei";i:2;b:1;}s:6:"string";s:3:"abc";s:4:"bool";b:1;s:5:"bool2";b:0;s:7:"integer";i:1;s:8:"integer2";i:17;}

You may notice that all booleans are stored as a string ( b:1 = s:1:"1")

The problem is only in some installations of WordPress, and not at all. I also checked the serialize function , which works correctly (returns b:1)

Also using get_post_meta

get_post_meta($post_ID, 'my-key', true);

and check the value with is_bool returns false (obviously)

EDIT: just noticed that integers are stored as strings

+4
1

update_post_meta update_metadata, , 119 , meta_value wp_unslash, - (, , stripslashes_deep)

serialize update_post_meta()

EDIT:
: 3.6.0 update_metadata 117 :

$meta_key = stripslashes($meta_key)

stripslashes - php-, .
3.6.0 :

$meta_key = wp_unslash($meta_key);

stripslashes meta_keys.

wordpress 3.6.0 .

+6

All Articles