Skip to content

Instantly share code, notes, and snippets.

@LinzardMac
Created May 19, 2017 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LinzardMac/0d1915dfe78fc68f0b3c64d50cf2cb41 to your computer and use it in GitHub Desktop.
Save LinzardMac/0d1915dfe78fc68f0b3c64d50cf2cb41 to your computer and use it in GitHub Desktop.
Pros/Cons of is_numeric()

is_numeric()

is_numeric() is a conditional that tests if the value passed is numeric and returns false if not.

Cons:

  • Does not do any sanitization of the input value
  • Will return true for values that could never or would never be a ID of a WordPress core object such as decimals (see truthy values below).
  • WordPress does not consistently create false cases for testing the results of any is_numeric condition tests thus no feedback upon failure.

Values is_numeric() considered valid:

  • +0123.45e6
  • 12.3456
  • 12345

Pros:

  1. is_numeric allows for the creation of a false condition whereby the function testing the condition could be notified of a false condition and adjust accordingly.
  2. Since is_numeric is a function, it can be passed to a function as a parameter that accepts functions such as array_map(‘is_numeric’, $array) for validation purposes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment