symfony/finder · error · InvalidArgumentException
Invalid number " ".
Error message
Invalid number "%s".
What it means
After NumberComparator's regex matched and captured a numeric-looking target, PHP's is_numeric() check failed on it — e.g. strings like '1.2.3' or '..' that match the loose [0-9\.]+ pattern but aren't valid numbers — so InvalidArgumentException is thrown with 'Invalid number'.
Solutions
- Supply a valid plain number with at most one decimal point: '10', '1.5'
- Sanitize input with filter_var($v, FILTER_VALIDATE_FLOAT) or is_numeric() before constructing
- Fix config parsing that concatenates or duplicates dots
Example fix
// before
$finder->size('> 1.2.3'); // matches regex but is_numeric fails
// after
$finder->size('> 1.2'); Defensive patterns
Strategy: validation
Validate before calling
if (!is_numeric($num)) { throw new \InvalidArgumentException("Not a valid number: $num"); } Type guard
function isPlainNumber(mixed $v): bool { return is_numeric($v) && substr_count((string) $v, '.') <= 1; } Try / catch
try { new NumberComparator('> 1.2'); } catch (\InvalidArgumentException $e) { /* handle invalid number */ } Prevention
- Run is_numeric() or filter_var(..., FILTER_VALIDATE_FLOAT) before constructing
- Reject inputs containing multiple dots
- Sanitize values that pass through string concatenation or config parsing
When it happens
Trigger: new NumberComparator('1.2.3'), ->size('..'), ->size('...5') — strings whose digit/dot-only pattern matches the regex but fail is_numeric().
Common situations: Malformed config values with multiple dots, typo'd decimal separators, concatenated strings producing '..' patterns.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Don't understand " " as a number test.
- Invalid operator " ".
- Don't understand " " as a date test.
- " " is not a valid date.
- Invalid PHP callback.
AI-assisted analysis of symfony/finder@4d6c057bfd (2026-09-13).
Data as JSON: /api/errors/02b7fe774170060a.
Report an issue: GitHub.
Appendix: source
Thrown at Comparator/NumberComparator.php:50
*
* @see http://physics.nist.gov/cuu/Units/binary.html
*/
class NumberComparator extends Comparator
{
/**
* @param string|null $test A comparison string or null
*
* @throws \InvalidArgumentException If the test is not understood
*/
public function __construct(?string $test)
{
if (null === $test || !preg_match('#^\s*(==|!=|[<>]=?)?\s*([0-9\.]+)\s*([kmg]i?)?\s*$#i', $test, $matches)) {
throw new \InvalidArgumentException(\sprintf('Don\'t understand "%s" as a number test.', $test ?? 'null'));
}
$target = $matches[2];
if (!is_numeric($target)) {
throw new \InvalidArgumentException(\sprintf('Invalid number "%s".', $target));
}
if (isset($matches[3])) {
// magnitude
switch (strtolower($matches[3])) {
case 'k':
$target *= 1000;
break;
case 'ki':
$target *= 1024;
break;
case 'm':
$target *= 1000000;
break;
case 'mi':
$target *= 1024 * 1024;
break;
case 'g':
$target *= 1000000000;View on GitHub (pinned to 4d6c057bfd)