php-liquid icon indicating copy to clipboard operation
php-liquid copied to clipboard

Autoloading issue: PSR-0 vs PSR-4

Open live627 opened this issue 3 years ago • 2 comments

Difference between psr-0 and psr-4

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

psr-0

Looking at vendor/composer/autoload_namespaces.php file you can see the namespaces and the directories that they are mapped to.

composer.json

"autoload": {
        "psr-0": {
            "Liquid\\": "src/"
        }
} 
  • Looking for Liquid\Template in src/Liquid/Template.php

psr-4

Looking at vendor/composer/autoload_psr4.php file you can see the namespaces and the directories that they are mapped to.

composer.json

"autoload": {
    "psr-4": {
        "Liquid\\": "src/"
    }
}   
  • Looking for Liquid\Template in src/Template.php

composer.json

"autoload": {
    "psr-4": {
        "Liquid\\": "src/Liquid/"
    }
}    
  • Looking for Liquid\Template in src/Liquid/Template.php

How to fix

Either

  • Move both sources and tests up one level
  • Change autoloader to specify psr-0

live627 avatar Feb 11 '23 03:02 live627

Looking for Liquid\Template in src/Liquid/Template.php

Isn't this is what we have in actuality?

sanmai avatar Feb 11 '23 04:02 sanmai

So, there is no bug, really, but an issue with not following the spec exactly.

live627 avatar Feb 11 '23 04:02 live627