The below code results in the error: Notice: Uninitialized string offset: 0
:
$defArray = array( "width" => "", "height" => "" );
$option = get_option( "myoption", $defArray );
//This throws the error
echo $option[ "width" ];
//This shows it as type "string"
var_dump( $option );
According to the docs, I should be able to pass a default value that gets returned if nothing is saved in that option (and nothing is, I just made it up). http://codex.wordpress.org/Function_Reference/get_option
Why is it not using the default value?
Somehow in refreshing the page, the option got created. I am not sure how as I never submitted the form. Calling
delete_option(...)
stopped the error from occurring.you can force the return by parsing args;