symfony/finder · error · InvalidArgumentException

Invalid operator " ".

Error message

Invalid operator "%s".

What it means

Comparator::validate() (invoked from the constructor) rejects any comparison operator outside the whitelist ['>', '<', '>=', '<=', '==', '!=']. The library throws InvalidArgumentException to fail fast when an operator string is misspelled or unsupported.

Solutions

  1. Use one of the exact operators: >, <, >=, <=, ==, !=
  2. Replace '=>' with '>=' and '=' with '==', '<>' with '!='
  3. Trim/normalize operator input before constructing the Comparator

Example fix

// before
$c = new Comparator('100', '=>');
// after
$c = new Comparator('100', '>=');
Defensive patterns

Strategy: validation

Validate before calling

$allowed = ['>', '<', '>=', '<=', '==', '!=']; if (!in_array($op, $allowed, true)) { throw new \InvalidArgumentException("Bad operator: $op"); }

Type guard

function isValidComparatorOp(mixed $op): bool { return is_string($op) && in_array($op, ['>','<','>=','<=','==','!='], true); }

Try / catch

try { $c = new Comparator($target, $op); } catch (\InvalidArgumentException $e) { /* handle invalid operator */ }

Prevention

When it happens

Trigger: Passing any operator string other than the six supported ones to new Comparator($target, $operator), e.g. '=>', '=', '<>', '===', or with stray whitespace.

Common situations: Handwritten Finder date/size comparisons, config files supplying operators as free-form strings, porting code that used '=>' or '===' from other expression languages.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of symfony/finder@4d6c057bfd (2026-09-13). Data as JSON: /api/errors/6efdc531829375b8. Report an issue: GitHub.

Appendix: source

Thrown at Comparator/Comparator.php:26

 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Comparator;

/**
 * @author Fabien Potencier <fabien@symfony.com>
 */
class Comparator
{
    private string $operator;

    public function __construct(
        private string $target,
        string $operator = '==',
    ) {
        if (!\in_array($operator, ['>', '<', '>=', '<=', '==', '!='], true)) {
            throw new \InvalidArgumentException(\sprintf('Invalid operator "%s".', $operator));
        }

        $this->operator = $operator;
    }

    /**
     * Gets the target value.
     */
    public function getTarget(): string
    {
        return $this->target;
    }

    /**
     * Gets the comparison operator.
     */
    public function getOperator(): string
    {

View on GitHub (pinned to 4d6c057bfd)