{"record":{"id":"5a58257062e56ac0","repo":"symfony/process","slug":"cannot-serialize-symfony-component-process-process","errorCode":null,"errorMessage":"Cannot serialize Symfony\\Component\\Process\\Process","messagePattern":"Cannot serialize Symfony\\\\Component\\\\Process\\\\Process","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"Process.php","lineNumber":218,"sourceCode":"     * @param string         $command The command line to pass to the shell of the OS\n     * @param string|null    $cwd     The working directory or null to use the working dir of the current PHP process\n     * @param EnvArray|null  $env     The environment variables or null to use the same environment as the current PHP process\n     * @param mixed          $input   The input as stream resource, scalar or \\Traversable, or null for no input\n     * @param int|float|null $timeout The timeout in seconds or null to disable\n     *\n     * @throws LogicException When proc_open is not installed\n     */\n    public static function fromShellCommandline(string $command, ?string $cwd = null, ?array $env = null, mixed $input = null, ?float $timeout = 60): static\n    {\n        $process = new static([], $cwd, $env, $input, $timeout);\n        $process->commandline = $command;\n\n        return $process;\n    }\n\n    public function __serialize(): array\n    {\n        throw new \\BadMethodCallException('Cannot serialize '.__CLASS__);\n    }\n\n    public function __unserialize(array $data): void\n    {\n        throw new \\BadMethodCallException('Cannot unserialize '.__CLASS__);\n    }\n\n    public function __destruct()\n    {\n        if ($this->options['create_new_console'] ?? false) {\n            $this->processPipes->close();\n        } else {\n            $this->stop(0);\n        }\n    }\n\n    public function __clone()\n    {","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/symfony/process/blob/99b85026db14a68f02c6f3eeb01a1170ca25c491/Process.php#L200-L236","documentation":"A Symfony Process object wraps an OS process, pipes, and mutable runtime state, none of which survives PHP serialization. Process::__serialize() therefore unconditionally throws BadMethodCallException to stop serialize() rather than producing a broken object.","triggerScenarios":"serialize($process), serialize() of an object holding a Process property (job/task objects, cache entries, session data), or passing a running Process through serialize-based transports.","commonSituations":"Storing pending/running tasks in cache or session with the Process embedded, serialize-based logging/debugging, legacy queue payloads containing Process instances.","solutions":["Store the command description (command line, cwd, env, timeout) and rebuild with new Process() when needed","Implement __sleep()/__serialize() on enclosing classes to exclude the Process property","Use a serializable value object (e.g. an id) and keep a process registry keyed by that id"],"exampleFix":"// before\n$payload = serialize(['process' => $process]);\n// after\n$payload = serialize(['commandline' => $process->getCommandLine(), 'cwd' => $process->getWorkingDirectory()]);","handlingStrategy":"type-guard","validationCode":"if ($obj instanceof \\Symfony\\Component\\Process\\Process) { throw new \\LogicException('Process objects are not serializable'); }","typeGuard":"function isSerializable(mixed $v): bool { try { serialize($v); return true; } catch (\\Throwable) { return false; } }","tryCatchPattern":"try { $payload = serialize($task); } catch (\\BadMethodCallException $e) { $payload = serialize($task->getDescriptor()); }","preventionTips":["Never store Process objects in session/cache/queue payloads","Use getCommandLine(), cwd and env as the serializable descriptor","Run a serialize() smoke test in unit tests for cacheable classes"],"tags":["serialization","process","unsupported-operation"],"backgroundTag":"json-serialization-failed","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"}