Should I use DIRECTORY_SEPARATOR or BAR (/)?

3

I usually tinker with the framework source code, as in the case of Laravel to see how structures are made. I noticed something interesting in Laravel 4 in relation to Laravel 3 .

In Laravel 3 , you use, to mount directory paths, the constant DS , which is a constant declared with DIRECTORY_SEPARATOR value.

Example:

path('public') . DS . 'index.php';

In the Laravel 4 , I see codes like the following:

app_storage() . '/views';

I know that this constant DIRECTORY_SEPARATOR is responsible for returning the separator character of directories according to the operating system that is being used.

I had this as important, but the Laravel 4 (which is a more current and more "inside" framework) of the php news) simply does not use DIRECTORY_SEPARATOR .

Does anyone know if this has to do with the old versions of PHP? I mean, in some version should I care about DIRECTORY_SEPARATOR and then, from a certain version, that's no longer important?

Is there really any difference in the way operating systems read directory separators (example: Ubuntu, Linux, MAC)?

I would like to know this, because I want to know if I can simply do this directly.

Example:

include_once __DIR__ . '/vendor/autoload.php';

Or you would have to do things to avoid the risk 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');
    
asked by anonymous 06.07.2015 / 18:03

1 answer

3

I think the use of the constant is not very elegant, it disturbs the directory reading, however with the use of a new constant as DS I think it valid, since it minimizes the impact on the application, however this is only relevant if your system can to be compatible with multiple platforms.

But most importantly, PHP automatically converts to / when needed, depending on the platform being run, so use without moderation.

I do not know what version this came to be, but all the latest ones are compatible, there are three links that confirm:

  • link
  • link
  • link
  • 06.07.2015 / 18:32