You are here

function cf_is_integer in Common Functionality 7.2

Determine if the argument is an integer.

Justification: The PHP function is_int() does not return TRUE for numeric strings. Doing a is_numeric() returns TRUE for floats. There is no way to test to see if a numeric string is an integer.

The test for ($argument == (int) $argument) does not work because PHP will auto-case both sides of the argument to an integer. The end result is that arguments that are floats will return TRUE when it should not.

References:

Parameters

string $argument: The argument to test if it is an integer.

Return value

bool Returns TRUE for an integer or a string that represents a valid integer. FALSE is returned for all non-integers, including floats.

Related topics

1 call to cf_is_integer()
cf_db_options_id_to_machine_name in modules/cf_db_options/cf_db_options.module
Returns the machine_name for a given option numeric id.

File

./cf.module, line 491
Common Functionality module.

Code

function cf_is_integer($argument) {
  if (!is_numeric($argument)) {
    return FALSE;
  }
  return (double) $argument === round($argument);
}