title: Redefining wrapper in PHP
body: <p>For one my project, I need to clone or redefine steam wrapper. I need to process all files thru some function before <code>require</code>, <code>fopen</code> etc. Basicly, it's like simulating virtual file system - PHP needs to get real file content modified.</p>
  
  <p>At this time, I solved this by defining my custom wrapper thru <code>stream_wrapper_register()</code> and requiring index file by <code>mywrapper://(original path)</code>. This workes, I solved even problems of modified file's filesize differences, but I have one mayor problem - all constants like <code>__dir__</code> and some functions returns paths with <code>mywrapper://</code> on beginning, which is not good - I don't want it.</p>
  
  <p>Best solution to this problem seems redefining <code>file://</code> instead of defining custom <code>mywrapper://</code>, because all file requests will be transferred to my class. I can even redefine file wrapper with no problem, PHP allows this. But new problem will appear - if I redefine file wrapper, I can't work with filesystem anymore. Even my custom wrapper can't load files now, because <code>file://</code> is the only wrapper which can work with files. Even <code>SplFileObject</code> relies on file wrapper, so I can't access file system this way.</p>
  
  <p>So what are best solutions?</p>
  
  <ol>
  <li>Set another default wrapper than file for paths without specifying wrapper - in this case, I will still be able to access files thru prepending <code>file://</code> <strong>But it seems PHP does not allow this</strong></li>
  <li>Redefine <code>file://</code> wrapper, but defining new custom wrapper with same function - technicly clone file wrapper to another and then redefine file wrapper. <strong>Again, it seems PHP does not allow this. I was trying to find if integrated file wrapper is registered class - in this case I can register it to another wrapper, but it seems it's not.</strong></li>
  </ol>
  
  <p>What are another workarounds?</p>
  
  <ol>
  <li>Make custom file functions like <code>fopen</code> which always restores previous file wrapper, use it and then re-register again custom wrapper - not a good solution, lot of re-registering and problem with nested functions.</li>
  <li>Make local FTP server on same machine and access real file system via ftp functions - again, not a brilliant solution, but it should work.</li>
  </ol>
  
  <p><strong>My question ... can anyone tell me if there is any option how to achieve one of the two best solutions or find another solution which would be working and wouldn't be nasty workaround?</strong></p>