In PHP, stream_wrapper_unregister() removes a protocol scheme from the list of active stream wrappers.
Use it to drop a custom scheme you registered, or to temporarily remove a built-in scheme before installing a replacement. It returns true on success. Restore built-ins later with stream_wrapper_restore().
Syntax
Call stream_wrapper_unregister() with the values you need. Start with this line.
PHP
$ok = stream_wrapper_unregister('demo');
Call
What it does
stream_wrapper_unregister('demo')
Removes the custom demo:// scheme.
stream_wrapper_unregister('http')
Temporarily removes the built-in http wrapper.
stream_wrapper_unregister($protocol)
Unregisters the scheme name stored in $protocol.
After unregister, fopen('demo://...') will fail for that scheme. Built-in schemes can be brought back with stream_wrapper_restore(). Custom schemes need stream_wrapper_register() again.
Library declarations
PHP
stream_wrapper_unregister(string $protocol): bool
Parameters
Parameter
Description
protocol
Required. The scheme name to remove, without ://.
Return Value
Return Value
Description
true
The protocol was unregistered.
false
The protocol could not be removed.
PHP Examples
Example 1 — Register Then Unregister
Register a stub scheme, unregister it, and show it is gone from the wrappers list.
PHP
<?php
class GoneStream {
public $context;
public function stream_open($path, $mode, $options, &$opened_path) { return true; }
public function stream_read($count) { return ''; }
public function stream_eof() { return true; }
public function stream_stat() { return []; }
}
stream_wrapper_register('gone', GoneStream::class);
stream_wrapper_unregister('gone');
echo in_array('gone', stream_get_wrappers(), true) ? 'still there' : 'removed', PHP_EOL;
Output
removed
How It Works
Register the gone protocol with a stub class.
stream_wrapper_unregister('gone') removes it.
stream_get_wrappers() no longer lists gone.
Later fopen('gone://x') would fail.
Example 2 — Boolean Result of Unregister
Print success when unregistering a scheme you just added.
PHP
<?php
class DropStream {
public $context;
public function stream_open($path, $mode, $options, &$opened_path) { return true; }
public function stream_read($count) { return ''; }
public function stream_eof() { return true; }
public function stream_stat() { return []; }
}
stream_wrapper_register('drop', DropStream::class);
$ok = stream_wrapper_unregister('drop');
echo $ok ? 'unregistered' : 'failed', PHP_EOL;
Output
unregistered
How It Works
Register drop:// first so unregister has a target.
unregister returns true on success.
false means the scheme was missing or could not be removed.
Use the result in tests and setup/teardown code.
Example 3 — Built-in Reminder
Document that built-in schemes should be restored after a temporary unregister.
PHP
<?php
// If you unregister a built-in such as http during a test:
// stream_wrapper_unregister('http');
// ... temporary replacement ...
// stream_wrapper_restore('http');
echo 'custom schemes: unregister is enough', PHP_EOL;
echo 'built-ins: restore afterward', PHP_EOL;
Output
custom schemes: unregister is enough
built-ins: restore afterward
How It Works
Custom schemes only need unregister when finished.
Built-ins should be restored for the rest of the request.
stream_wrapper_restore() brings the original handler back.
Avoid leaving core schemes disabled in production.
Frequently Asked Questions
It removes a protocol scheme so PHP no longer routes that URL prefix through a stream wrapper.
Call stream_wrapper_register() again with your class name.
Call stream_wrapper_restore() with the protocol name.
Existing open streams may continue until closed, but new opens for that scheme fail. Prefer clean setup/teardown around tests.
The protocol was not registered, or PHP could not remove it.