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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 352386674 at qq dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Thu Oct 31 23:01:28 2024 UTC