Req #50526 [Opn->Csd]: stat() needs Context parameter

From: Date: Wed, 21 Jul 2021 09:44:54 +0000
Subject: Req #50526 [Opn->Csd]: stat() needs Context parameter
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235224@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=50526&edit=1

 ID:                 50526
 Updated by:         cmb@php.net
 Reported by:        codeslinger at compsalot dot com
 Summary:            stat() needs Context parameter
-Status:             Open
+Status:             Closed
 Type:               Feature/Change Request
-Package:            *General Issues
+Package:            Streams related
 Operating System:   any
 PHP Version:        5.2.12
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

> but the "stat" family of functions is limited by the lack of a
> "context" param.

You should be able to use stream_context_set_default()[1].

> And it seems that StreamWrapper stat doesn't use default context
> either.

The behavior is documented[2].

[1] <https://www.php.net/stream_context_set_default>
[2] <https://www.php.net/manual/en/class.streamwrapper.php#streamwrapper.props>


Previous Comments:
------------------------------------------------------------------------
[2013-10-04 13:00:04] matti dot jarvinen at nitroid dot fi

And it seems that StreamWrapper stat doesn't use default context either.

$options = array('testfs'=> array(
   'storagePath'=>dirname(ROOTPATH).DIRECTORY_SEPARATOR.'storage'
   )
);

$defaultContext = stream_context_get_options(stream_context_get_default());

$newContext = array_replace_recursive($defaultContext, $options);

stream_context_set_default($newContext);

stream_wrapper_register('testfs', 'Test_StreamWrapper');

class Test_StreamWrapper
{
  public $context;

  public function url_stat()
  {
    if($this->context === null)
    {
       print 'No Context!';   
    }
    return false;
  }
}

file_exists('testfs://foobar');

Expected:

Got:
No Context!

------------------------------------------------------------------------
[2009-12-21 22:37:11] lbarnaud@php.net

For stream_wrappers, by calling fopen() with a context parameter and then fstat() on the opened
stream, you should be able to pass a context (the ->context attribute in the wrapper's
instance).

------------------------------------------------------------------------
[2009-12-18 21:36:59] codeslinger at compsalot dot com

Description:
------------
Feature Request:

the stream wrapper functions are *totally awesome*  :-)  !!!

but the "stat" family of functions is limited by the lack of a "context" param.

For instance I need to be able to provide a user name and password for a particular connection.  for
opendir mkdir fopen etc.  I am able to pass a context with that info and everything works.  But then
when I try to do a "stat" or "fstat"  it fails because there is no way to pass
the $context.

Thank you for making PHP such a fantastic programming language!


Reproduce code:
---------------
---
From manual page: streamwrapper.stream-stat#Description
---


Actual result:
--------------
also see related 
Bug #42965  	copy() should support context parameters for URLs




------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=50526&edit=1


Thread (6 messages)

« previous php.bugs (#235224) next »