Opened 5 years ago
Last modified 5 years ago
#50181 new defect (bug)
Second params of get_option() not used
Reported by: | sebastienserre | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.4.1 |
Component: | Options, Meta APIs | Keywords: | 2nd-opinion dev-feedback |
Focuses: | Cc: |
Description
Hello
In a develp=opment I have something like
$options = get_option( 'my_option', array() ); foreach ( $options as $option ) { // doing things }
The option stored seems to be not unserializable.
So when going through https://github.com/WordPress/WordPress/blob/master/wp-includes/option.php#L152 + unserialize() which return false on error the second parameter is not used and we got a Warning.
We're not testing $options
thinking with the second param setted to array()
will allways return an array...
Change History (3)
#2
@
5 years ago
OK, so I got false
, the option is not surrounded by array()
that seems logical and it doesn't save a test.
#3
@
5 years ago
- Keywords 2nd-opinion dev-feedback added
I think, but advice from more experienced developers than me is more than welcome, the second params should be relevant if the maybe_unserialize can't unserialize and return false.
I also understand that an option can also be "false" so not an easy way... but surely something to do.
That line of code is only encountered when there is a value in the option, and when there is, the default (second parameter) is not relevant.