close(); * rewind($f); // error, $f is a closed resource * ``` * * Instead, this would work: * * ``` * $stream = Psr7\Utils::streamFor(fopen('php://temp', 'r+')); * $test = new NonClosingStream($stream); * // work * $test->close(); * $stream->rewind(); // works * ``` * * @author Zaahid Bateson */ class NonClosingStream implements StreamInterface { use StreamDecoratorTrait; /** * @var ?StreamInterface $stream * @phpstan-ignore-next-line */ private $stream; /** * @inheritDoc */ public function close(): void { $this->stream = null; } /** * Overridden to detach the underlying stream without closing it. * * @inheritDoc */ public function detach() { $this->stream = null; return null; } }