phacility/phabricator · error · Exception

Value for "number" argument must be an integer or double, go

Error message

Value for "number" argument must be an integer or double, got %s.

What it means

For 'number' typed chart function arguments, PhabricatorChartFunctionArgument::newValue() accepts only PHP int or float. Anything else — numeric strings, null, booleans — throws this Exception with the actual type from phutil_describe_type().

Source

Thrown at src/applications/fact/chart/PhabricatorChartFunctionArgument.php:131

              'beginning with a function name as a string. The first list '.
              'item has the wrong type, %s.',
              phutil_describe_type($function_name)));
        }

        $functions = PhabricatorChartFunction::getAllFunctions();
        if (!isset($functions[$function_name])) {
          throw new Exception(
            pht(
              'Function "%s" is unknown. Valid functions are: %s',
              $function_name,
              implode(', ', array_keys($functions))));
        }

        return id(clone $functions[$function_name])
          ->setArguments($value);
      case 'number':
        if (!is_float($value) && !is_int($value)) {
          throw new Exception(
            pht(
              'Value for "number" argument must be an integer or double, '.
              'got %s.',
              phutil_describe_type($value)));
        }

        return $value;
    }

    throw new PhutilMethodNotImplementedException();
  }

}

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Cast to int/float before use: (int)$value or (float)$value when the source is a string parameter.
  2. Validate with is_int($v) || is_float($v) during spec construction.
  3. Reject null/boolean early at the request boundary.
  4. Note there is no string coercion: strict typing is intentional.

Example fix

// before
$arguments[] = $request->getValue('limit'); // '100' (string) -> Exception

// after
$limit = $request->getValue('limit');
$arguments[] = (int)$limit;
Defensive patterns

Strategy: type-guard

Type guard

function is_chart_number($value) {
  return is_int($value) || is_float($value);
}

Prevention

When it happens

Trigger: Passing '7' (string) instead of 7, null from a missing key, or true/false as a number argument, e.g. array('constant', '100') from unvalidated request or JSON input.

Common situations: HTTP/Conduit request values arriving as strings and used unvalidated; JSON decoding configured to produce strings; idx() defaults of null flowing into argument lists; form inputs never cast.

Understand the failure class

Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/aad197b566711b4c. Report an issue: GitHub.