What Are the Differences Between PSR-0 and PSR-4?

前端 未结 5 586
野性不改
野性不改 2020-11-28 00:34

Recently I\'ve read about namespaces and how they are beneficial. I\'m currently creating a project in Laravel and trying to move from class map autoloading to namespacing.

5条回答
  •  醉梦人生
    2020-11-28 01:24

    PSR-4 is something like 'relative path', PSR-0, 'absolute path'.

    e.g.

    config:

    'App\Controller' => 'dir/'
    

    PSR-0 autoload:

    App\Controller\IndexController --> dir/App/Controller/IndexController.php
    

    PSR-4 autoload:

    App\Controller\IndexController --> dir/IndexController.php
    

    And there are some more difference in details between PSR-0 and PSR-4, see here: http://www.php-fig.org/psr/psr-4/

提交回复
热议问题