Voting

: one minus zero?
(Example: nine)

The Note You're Voting On

Hayley Watson
5 years ago
Even though their names will be the same, you can have more than one //memory or //temp stream open concurrently; each time you fopen() such a stream, a NEW stream will be opened independently of the others.

This is hinted at by the fact you don't add any unique identifier to the path when creating such streams, but isn't said explicitly.

<?php

$hello
= fopen('php://memory', 'r+'); // $hello, $php, $world are all different streams.
$php  = fopen('php://memory', 'r+');
$world = fopen('php://memory', 'r+'); // They're not the same stream opened three times.

fputs($hello, "Hello ");
fputs($php, "PHP ");
rewind($php);
fputs($world, "World!");
rewind($hello);
rewind($world);

echo
'[', stream_get_contents($hello), '][', stream_get_contents($php), '][', stream_get_contents($world), ']';
// If they were the same stream the output would be "[World!][World!][World!]".
?>

<< Back to user notes page

To Top