{"record":{"id":"35f42b357036fb1f","repo":"symfony/process","slug":"s-only-accepts-strings-traversable-objects-or-stream","errorCode":null,"errorMessage":"\"%s\" only accepts strings, Traversable objects or stream resources.","messagePattern":"\"(.+?)\" only accepts strings, Traversable objects or stream resources\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"ProcessUtils.php","lineNumber":59,"sourceCode":"    {\n        if (null !== $input) {\n            if (\\is_resource($input)) {\n                return $input;\n            }\n            if (\\is_scalar($input)) {\n                return (string) $input;\n            }\n            if ($input instanceof Process) {\n                return $input->getIterator($input::ITER_SKIP_ERR);\n            }\n            if ($input instanceof \\Iterator) {\n                return $input;\n            }\n            if ($input instanceof \\Traversable) {\n                return new \\IteratorIterator($input);\n            }\n\n            throw new InvalidArgumentException(\\sprintf('\"%s\" only accepts strings, Traversable objects or stream resources.', $caller));\n        }\n\n        return $input;\n    }\n}\n","sourceCodeStart":41,"sourceCodeEnd":65,"githubUrl":"https://github.com/symfony/process/blob/99b85026db14a68f02c6f3eeb01a1170ca25c491/ProcessUtils.php#L41-L65","documentation":"ProcessUtils::validateInput() validates the $input argument supplied to Process::setInput(), setStdin (write), etc. Only strings, Traversable objects and stream resources are accepted; anything else (e.g. int, array, object without Traversable) throws InvalidArgumentException naming the caller method.","triggerScenarios":"Calling Process::setInput($value) or $process->write($value) (or a constructor path that resolves input) with an unsupported type such as an int, float, bool, array, or a plain non-Traversable object.","commonSituations":"Passing an integer/numeric value from user input, passing a stdClass or DTO object expecting it to be stringified, or passing an array of bytes instead of a string.","solutions":["Cast the value to string before passing: setInput((string) $value)","Convert arrays/objects to a string (json_encode, serialize, or iterate into a string) before use","If you have a Traversable, pass it directly — it is wrapped in an IteratorIterator automatically","If the value is a resource, keep it as an open stream resource rather than reading it into memory"],"exampleFix":"// before\n$process->setInput(12345);\n// after\n$process->setInput((string) 12345);","handlingStrategy":"type-guard","validationCode":"if (!is_string($input) && !$input instanceof \\Traversable && !is_resource($input)) { throw new \\TypeError('Process input must be string, Traversable or resource'); }","typeGuard":"function isValidProcessInput(mixed $v): bool { return is_string($v) || $v instanceof \\Traversable || is_resource($v); }","tryCatchPattern":"try { $process->setInput($input); } catch (\\InvalidArgumentException $e) { $process->setInput((string) $input); }","preventionTips":["Cast scalars with (string) before setInput()/write()","Never pass arrays; convert to JSON or a string first","Remember resources must remain open streams, not file paths","Add a helper that normalizes input types before creating a Process"],"tags":["process","input","type-mismatch","argument-error"],"backgroundTag":"type-mismatch","analyzedSha":"99b85026db14a68f02c6f3eeb01a1170ca25c491","analyzedAt":"2026-09-14T11:23:33.683Z","contentChangedAt":"2026-09-14T11:23:33.683Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}