title: PHP directory separators, forcing forward slash; non-intrusive
body: <p>Whenever I work with PHP (<em>often</em>) I typically work on a Windows box, however I (<em>try to</em>) develop platform agnostic applications; one major point of issue being the use of directory separators.</p>
  
  <p>As many know, doing any filesystem work in a Windows environment in PHP, you can use forward slashes in lieu of backwards, and PHP sorts it out under the hood. This is all fine when it comes to using string literals to pass a path to <code>fopen()</code> or whatever; but when retrieving paths, be it <code>__FILE__</code> or expanding with <code>realpath()</code>, the paths retrieved are of course using the OS appropriate slashes. Also, I've noticed some inconsistencies in trailing slashes. Once or twice <code>__DIR__</code> has appended one (<em>a backslash</em>) and <code>realpath()</code> too (<em>I prefer the trailing slash, but not intermittently</em>)</p>
  
  <p>This is clearly a problem for string comparison, because instead of doing:</p>
  
  <pre><code>compare_somehow('path/to/file.php', __DIR__);
  </code></pre>
  
  <p>For the sake of reliability, I'm having to go:</p>
  
  <pre><code>compare_somehow('path/to/file.php', rtrim(strtr(__DIR__, '\\', '/'), '/') . '/');
  </code></pre>
  
  <p>This seems like alot of work. I can drop it into a function, sure; now I'm stuck with an arbitrary function dependency in all my OO code.</p>
  
  <p>I understand that PHP isn't perfect, and accommodations need to be made, but surely there must exist some platform agnostic workaround to force filesystem hits to retrieve forward slashed paths, or at least a non-intrusive way to introduce a class-independent function for this purpose.</p>
  
  <p>Summary question(<em>s</em>):</p>
  
  <ul>
  <li>Is there some magical (<em>though reliable</em>) workaround, hack, or otherwise to force PHP to kick back forward slashed filesystem paths, regardless of the server OS?</li>
  <li>I'm going to assume the answer is <em>no</em> to the above, so moving on; what provisions can I make to enforce forward slash (<em>or whatever choice, really</em>) as the directory separator? I'm assuming through the aforementioned filter function, but now where should it go?</li>
  </ul>
  
  <hr>
  
  <p>Forward slash for everything. Even if the host OS separator is <code>#*&amp;@</code>.</p>