PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception

Invalid rule connection for column AutoFilter.

Error message

Invalid rule connection for column AutoFilter.

What it means

Column::setJoin() lowercases the input and validates it against the allowed join words 'and' and 'or', which control how multiple custom-filter rules combine. Any other string is rejected.

Source

Thrown at src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php:201

    public function getJoin(): string
    {
        return $this->join;
    }

    /**
     * Set AutoFilter Multiple Rules And/Or.
     *
     * @param string $join And/Or
     *
     * @return $this
     */
    public function setJoin(string $join): static
    {
        $this->setEvaluatedFalse();
        // Lowercase And/Or
        $join = strtolower($join);
        if (!in_array($join, self::$ruleJoins)) {
            throw new PhpSpreadsheetException('Invalid rule connection for column AutoFilter.');
        }

        $this->join = $join;

        return $this;
    }

    /**
     * Set AutoFilter Attributes.
     *
     * @param (float|int|string)[] $attributes
     *
     * @return $this
     */
    public function setAttributes(array $attributes): static
    {
        $this->setEvaluatedFalse();
        $this->attributes = $attributes;

View on GitHub (pinned to 65b080eef4)

Solutions

  1. Pass only 'and' or 'or' (any case)
  2. Normalize incoming data with strtolower() plus a whitelist check before calling setJoin()

Example fix

// before
$column->setJoin($userJoin); // e.g. '&&'

// after
$join = strtolower($userJoin);
$column->setJoin(in_array($join, ['and', 'or'], true) ? $join : 'and');
Defensive patterns

Strategy: validation

Validate before calling

$join = strtolower($join);
if (!in_array($join, ['and', 'or'], true)) {
    $join = 'and';
}
$column->setJoin($join);

Type guard

function isValidRuleJoin(string $join): bool
{
    return in_array(strtolower($join), ['and', 'or'], true);
}

Try / catch

try {
    $column->setJoin($join);
} catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
    $column->setJoin('and');
}

Prevention

When it happens

Trigger: ->setJoin('AND') works (it is lowercased), but ->setJoin('&'), ->setJoin('plus') or ->setJoin('') throws.

Common situations: Passing boolean connectors from other formats ('&&', 'AND ' with whitespace is trimmed? not trimmed) or user-supplied join words straight into the API.

Related errors


AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17). Data as JSON: /api/errors/e7ea955bc42b0cd0. Report an issue: GitHub.