PHP Function Reference

PHP stream_wrapper_restore() Function



The PHP stream_wrapper_restore() function restores a built-in wrapper previously unregistered with stream_wrapper_unregister() function.

Syntax

stream_wrapper_restore(protocol)

Parameters

protocol Required. Specify the wrapper name which need to be restored.

Return Value

Returns true on success or false on failure.

Example:

The example below shows the usage of stream_wrapper_restore() function.

<?php
class VariableStream {
  //codes to implement methods like
  //stream_open, stream_write etc.
}

//checking the existence of 'var' stream
//wrapper, if exists unregister it 
$existed = in_array("var", stream_get_wrappers());
if ($existed) {
  stream_wrapper_unregister("var");
}

//register 'var' stream wrapper
stream_wrapper_register("var", "VariableStream");

//opening the file
$fp = fopen("var://test.txt", "w+");

//writing some content to it
fwrite($fp, "line1 content\n");
fwrite($fp, "line2 content\n");
fwrite($fp, "line3 content\n");

//getting the starting position of the file
rewind($fp);

//reading the content of the file
while (!feof($fp)) {
  echo fgets($fp);
}

//closing the file
fclose($fp);

//restore the 'var' stream wrapper
//if previously existed
if ($existed) {
  stream_wrapper_restore("var");
}
?>

The output of the above code will be:

line1 content
line2 content
line3 content

❮ PHP Streams Reference