Why is the underscore converted to a directory delimiter in the PSR-0 standard?

The PSR-0 standard ( https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md ) indicates that the underscore in the class name should be converted to a directory separator in the corresponding name file.

This doesn’t seem like a good idea to me, because it creates a lot of errors when someone who does not know the standard innocently uses the underscore in the class name, and suddenly the autoloader cannot find the class and all kinds of strange errors (see this stackoverflow problem, for example: Symfony2.1 mapping error: class_parents () )

So, I suppose there must be some reason for this "function" (historical compatibility with some library?). My question is: does anyone know why this was introduced in the PSR-0 standard?

+5
source share
3 answers

Underscores were used at a time when PHP did not yet support namespaces. A “right” organized project follows the agreement of namespacing files in the same way as the directory structure.

This is just some general rule for organizing files in a project.

So, if you have a directory structure:

root
  Name
    Package
      MyClass.php

Formerly people:

class Name_Package_MyClass {}

But now that we have namespaces, it becomes:

namespace Name\Package;

class MyClass { }

This is just a coding style style that ensures everyone does the same.

, PSR-0, , namespacing .

+4

PHP 5.3, (), : My_Project_ClassName /path/to/my/My/Project/ClassName. , .

+1

, PSR-0 . : " , , , ". PSR-0 , , . , .

+1

All Articles