{"record":{"id":"fda6c44a3bb6e210","repo":"mongodb/laravel-mongodb","slug":"2nd-argument-of-s-must-be-null-when-1st-argument-is-an-array","errorCode":null,"errorMessage":"2nd argument of %s() must be \"null\" when 1st argument is an array. Got \"%s\" instead.","messagePattern":"2nd argument of (.+?)\\(\\) must be \"null\" when 1st argument is an array\\. Got \"(.+?)\" instead\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Query/Builder.php","lineNumber":1095,"sourceCode":"     * Append one or more values to an array.\n     *\n     * @param  string|array $column\n     * @param  mixed        $value\n     * @param  bool         $unique\n     *\n     * @return int\n     */\n    public function push($column, $value = null, $unique = false)\n    {\n        // Use the addToSet operator in case we only want unique items.\n        $operator = $unique ? '$addToSet' : '$push';\n\n        // Check if we are pushing multiple values.\n        $batch = is_array($value) && array_is_list($value);\n\n        if (is_array($column)) {\n            if ($value !== null) {\n                throw new InvalidArgumentException(sprintf('2nd argument of %s() must be \"null\" when 1st argument is an array. Got \"%s\" instead.', __METHOD__, get_debug_type($value)));\n            }\n\n            $query = [$operator => $column];\n        } elseif ($batch) {\n            $query = [$operator => [(string) $column => ['$each' => $value]]];\n        } else {\n            $query = [$operator => [(string) $column => $value]];\n        }\n\n        return $this->performUpdate($query);\n    }\n\n    /**\n     * Remove one or more values from an array.\n     *\n     * @param  string|array $column\n     * @param  mixed        $value\n     *","sourceCodeStart":1077,"sourceCodeEnd":1113,"githubUrl":"https://github.com/mongodb/laravel-mongodb/blob/0634653039468ceb0268a69192bdac64469ed043/src/Query/Builder.php#L1077-L1113","documentation":"Thrown by push()/pullAll-style batch APIs when the first argument is an array of column names but a non-null second argument is also supplied. When pushing to multiple columns, each column's value must be given inside the array itself; a scalar $value is only valid with a single string column.","triggerScenarios":"->push(['tags', 'votes'], 'like') — array column list combined with a scalar value; correct forms are ->push('tags', 'like') (single column) or ->push(['tags' => ['a'], 'votes' => [1]]) (per-column values).","commonSituations":"Mass-assignment style calls where devs assume the 2nd argument applies to every column; porting code from other builders that accept a default value per column.","solutions":["If pushing to one column: pass a string column name and the value as the 2nd argument.","If pushing to multiple columns: pass [$column => $value, ...] and remove the 2nd argument (pass null).","Wrap the value for each key in an array when pushing lists, e.g. ->push(['tags' => ['php']])."],"exampleFix":"// before\n$query->push(['tags', 'votes'], 'like');\n// after\n$query->push(['tags' => ['like'], 'votes' => [1]]);","handlingStrategy":"validation","validationCode":"if (is_array($column) && $value !== null) {\n    throw new InvalidArgumentException('Use [$col => $value] form and drop the 2nd argument');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never mix array column list with scalar value.","Prefer the single-column push form when possible.","Document the two calling conventions in team helpers."],"tags":["php","laravel-mongodb","argument-validation"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"0634653039468ceb0268a69192bdac64469ed043","analyzedAt":"2026-09-15T02:56:37.067Z","contentChangedAt":"2026-09-15T02:56:37.067Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}