Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 8 years ago

#28170 closed enhancement (fixed)

Add utility method for casting a var to boolean

Reported by: wonderboymusic's profile wonderboymusic Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.0 Priority: normal
Severity: normal Version: 4.0
Component: General Keywords: has-patch
Focuses: Cc:

Description

Because PHP can be configured without --filter, it is not 100% safe to use filter_var(). This is problematic for casting "false" to false, as PHP always casts it to true. FILTER_VALIDATE_BOOLEAN fixes this, but it may not be available.

Proposed new function: wp_validate_boolean().

Attachments (1)

28170.diff (645 bytes) - added by wonderboymusic 11 years ago.

Download all attachments as: .zip

Change History (4)

This ticket was mentioned in IRC in #wordpress-dev by wonderboymusic. View the logs.


11 years ago

#2 @wonderboymusic
11 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 28542:

Because PHP can be configured without --filter, it is not 100% safe to use filter_var(). This is problematic for casting "false" to false, as PHP always casts it to true. FILTER_VALIDATE_BOOLEAN fixes this, but it may not be available.

Add a new function, wp_validate_boolean(), to replace filter_var( $var, FILTER_VALIDATE_BOOLEAN ).

Fixes #28170.

This ticket was mentioned in Slack in #core-restapi by ocean90. View the logs.


8 years ago

Note: See TracTickets for help on using tickets.