php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80919 stream wrapper register first params prompt failed If underlined
Submitted: 2021-03-30 14:59 UTC Modified: 2021-03-30 15:07 UTC
From: 352386674 at qq dot com Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 7.4.16 OS: Ubuntu PHP version 7.4.8(cli)
Private report: No CVE-ID: None
 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-30 15:04 UTC] pollita@php.net
-Status: Open +Status: Not a bug
 [2021-03-30 15:04 UTC] pollita@php.net
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.
 [2021-03-30 15:07 UTC] pollita@php.net
Actually, on a second look, while your repro script is buggy, the real issue is that underscores are not valid scheme names.

Scheme names must contain ONLY [a-zA-Z0-9.+-] and no other characters.

This doesn't appear to be well documented, so I'll add a section to the manual.
 [2021-03-30 15:17 UTC] 352386674 at qq dot com
Sorry for the carelessness! Thank you for your explanation in the document
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 16:01:29 2024 UTC