Make WordPress Core

Opened 2 years ago

Closed 21 months ago

Last modified 20 months ago

#55359 closed defect (bug) (wontfix)

get_option return value wrong

Reported by: malthert's profile malthert Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords:
Focuses: docs Cc:

Description

https://developer.wordpress.org/reference/functions/get_option/

says it can return scalar including integer, which is false.

get_option can only return:
bool|null|string|array|object

Need to fix in phpdoc and documentation.

Change History (4)

#1 @malthert
2 years ago

EDIT, it's actually:
bool|string|array|object

Only if $default is set to null (or int/float) then it can return those, in case the option isn't found. However this is misleading in the documentation

Last edited 2 years ago by malthert (previous) (diff)

#2 @johnbillion
2 years ago

  • Focuses docs added

This function can return a value of any type because of the $default parameter:

get_option( 'i_dont_exist', 123 );

The @return documentation could do with improvement here but the return types look correct.

#3 @malthert
21 months ago

  • Resolution set to wontfix
  • Status changed from new to closed

Just @psalm-param it now in my stubs with a conditional ? return type

#4 @desrosj
20 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.