3
I often fiddle with frameworks source code, as in the case of Laravel to see how the structures are made. I noticed something interesting in Laravel 4 in relation to the Laravel 3.
In the Laravel 3, to mount directory paths, the constant DS, which is a declared constant with the value of DIRECTORY_SEPARATOR.
Example:
path('public') . DS . 'index.php';
Already in the Laravel 4, see codes as the following:
app_storage() . '/views';
I know that constant DIRECTORY_SEPARATOR is responsible for returning the directory separator character according to the operating system you are using.
I had it as important, but the Laravel 4 (which is a more current framework and more "inside" of the new php) simply does not use DIRECTORY_SEPARATOR.
Does anyone know if this has to do with old versions of PHP? I mean, in some version I should care about DIRECTORY_SEPARATOR and then, from a certain version, this is no longer important?
There is actually some difference in the way operating systems read directory separators (example: Ubuntu, Linux, MAC)?
I’d like to know that, because I want to know if I can just do it straight
Example:
include_once __DIR__ . '/vendor/autoload.php';
or would have to do things to avoid risks of conflicts in operating systems, as in the example below:
function my_path($path)
{
return str_replace(['\\', '//'], DIRECTORY_SEPARATOR, $path);
}
include_once __DIR__ . my_path('/vendor/autoload.php');
This question may help clarify your doubt: http://answall.com/questions/2304/diff%C3%A7a-entre-path-separator-e-directory-separator
– Delfino
@Delfino, you can’t really help.
DIRECTORY_SEPARATORis used to separate folders/etc/apache2. ThePATH_SEPARATORis something else. It is a kind of path separator for the windows environment variables, for example.c:\python;c:\ruby– Wallace Maxters
Correct Wallace, but look at the entire publication, it also speaks of
DIRECTORY_SEPARATOR. It seems to me you already have the answer. :)– Delfino
@Delfino, I saw there that they explain what it is
DIRECTORY_SEPARATOR. But I think it’s important also if I can simply use the/, or if I should still use onlyDIRECTORY_SEPARATOR– Wallace Maxters