Skip to content

Stream: detach Example

Terry L edited this page Jun 20, 2020 · 2 revisions
Clone this wiki locally

Shieldon\Psr7\Stream

detach()

Separates any underlying resources from the stream. After the stream has been detached, the stream is in an unusable state.

  • return resource|null

Example:

$stream = new Stream(fopen('php://temp', 'r+'));
/* ... do something ... */
$legacy = $stream->detach();

if (is_resouce($legacy)) {
    echo 'Resource is detached.';
}
// Outputs: Resource is detached.

$legacy = $stream->detach();

if (is_null($legacy)) {
    echo 'Resource has been null.';
}
// Outputs: Resource has been null.