| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2021-03-30 14:59 UTC] 352386674 at qq dot com
 Description:
------------
<?php
  
class StreamDir
{
    public $context = NULL;
 
    public function dir_opendir(string $path, int $options)
    {
        return false;
    }
}
$wrapper_list = stream_get_wrappers();
if(in_array('diy', $wrapper_list))
{
    echo "stream wrapper already\n";
    exit(0);
}
stream_wrapper_register("dir", "StreamDir");
$context = stream_context_create(['dir' => []]);
$dir = opendir('dir://Directory path', $context);
var_dump($dir);
Test script:
---------------
<?php
  
class StreamDir
{
    public $context = NULL;
 
    public function dir_opendir(string $path, int $options)
    {
        return false;
    }
}
$wrapper_list = stream_get_wrappers();
if(in_array('diy_wrapper', $wrapper_list))
{
    echo "stream wrapper already\n";
    exit(0);
}
stream_wrapper_register("dir_wrapper", "StreamDir");
$context = stream_context_create(['dir_wrapper' => []]);
$dir = opendir('dir_wrapper://Directory path', $context);
var_dump($dir);
Expected result:
----------------
tips open directory failed
Actual result:
--------------
Warning: stream_wrapper_register(): Invalid protocol scheme specified. Unable to register wrapper class StreamDir to dir_wrapper:// in PHP run script path
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 02:00:01 2025 UTC | 
There is a bug in your repro script: if(in_array('diy_wrapper', $wrapper_list)) "diy" != "dir" If you had the correct test there, you would see that your wrapper is already defined.