Emanuele Crema
Emanuele Crema

Reputation: 23

Difference between using "file://" stream wrapper or put directly file path (PHP)

I read on another topic that

file('file:///path/to/file.txt'); file('/path/to/file.txt');

are equivalent. So, what's the point to use file:// stream wrapper?

Are there some cases where there are some differences?

Upvotes: 0

Views: 137

Answers (1)

Open AI - Opting Out
Open AI - Opting Out

Reputation: 1631

No, well maybe yes...

They both use the file:/ stream wrapper, yes.

However, if you register a different wrapper for the file:// protocol, than PHP's, which while fun to implement, it's not a good idea, as you will loose almost all optimizations.

If you did, both require 'somefile.txt' and require 'file://somefile.txt' would be equivalent, as in they would both be using the same stream wrapper, but that stream wrapper may not be PHP's default one.

Upvotes: 1

Related Questions