In PHP, stream_wrapper_restore() restores a previously unregistered built-in protocol wrapper.
After stream_wrapper_unregister('http') or similar, call stream_wrapper_restore('http') to bring the original handler back. It returns true on success. Use this when you temporarily replace a built-in scheme for a test, then want the default behavior again.
Syntax
Call stream_wrapper_restore() with the values you need. Start with this line.
PHP
$ok = stream_wrapper_restore('http');
Call
What it does
stream_wrapper_restore('http')
Restores the built-in http wrapper after unregister.
stream_wrapper_restore('file')
Restores the built-in file wrapper if it was unregistered.
stream_wrapper_restore($protocol)
Restores whatever built-in scheme name is in $protocol.
Restore is meant for built-in wrappers you removed with stream_wrapper_unregister(). It does not recreate a custom class you registered yourself. For custom schemes, register again with stream_wrapper_register().
Library declarations
PHP
stream_wrapper_restore(string $protocol): bool
Parameters
Parameter
Description
protocol
Required. The built-in scheme name to restore, such as http or file.
Return Value
Return Value
Description
true
The built-in wrapper was restored.
false
Restore failed.
PHP Examples
Example 1 — Restore After Unregister Sketch
Show the unregister-then-restore sequence with fixed tutorial output.
PHP
<?php
// Example flow for a built-in scheme:
// stream_wrapper_unregister('http');
// ... temporary custom http handler ...
// stream_wrapper_restore('http');
echo 'restore target: http', PHP_EOL;
echo 'on success: true', PHP_EOL;
Output
restore target: http
on success: true
How It Works
Unregister the built-in scheme first.
Optionally register a temporary replacement.
stream_wrapper_restore() puts the original back.
true means the built-in handler returned.
Example 2 — Custom Scheme Uses Register Again
Demonstrate that a custom protocol is brought back with register, not restore.
PHP
<?php
class TempStream {
public $context;
public function stream_open($path, $mode, $options, &$opened_path) { return true; }
public function stream_read($count) { return 'x'; }
public function stream_eof() { return true; }
public function stream_stat() { return []; }
}
stream_wrapper_register('tempdemo', TempStream::class);
stream_wrapper_unregister('tempdemo');
$ok = stream_wrapper_register('tempdemo', TempStream::class);
echo $ok ? 'custom scheme back' : 'failed', PHP_EOL;
Output
custom scheme back
How It Works
Register a custom tempdemo scheme.
Unregister removes it.
Register again to restore a custom class.
stream_wrapper_restore() is for built-ins, not this case.
Example 3 — Confirm Wrappers List Idea
Print a fixed reminder to check stream_get_wrappers() after restore.
PHP
<?php
echo 'after restore, check stream_get_wrappers()', PHP_EOL;
echo 'built-in schemes reappear in that list', PHP_EOL;
Output
after restore, check stream_get_wrappers()
built-in schemes reappear in that list
How It Works
stream_get_wrappers() lists active schemes.
A restored built-in should appear again.
Use the list while debugging register/unregister mistakes.
Keep production code from unregistering core schemes casually.
Frequently Asked Questions
It restores a built-in protocol wrapper that was removed with stream_wrapper_unregister().
No. For custom schemes, call stream_wrapper_register() again with your class.
When a test temporarily replaces a built-in like http and must put the original handler back.
Restore failed, for example if the protocol was not a restorable built-in wrapper.
Check the boolean return and confirm the scheme appears in stream_get_wrappers().