Questions tagged [psr-4]

PSR-4 describes requirements that must be adhered to for autoloader interoperability in PHP. PSR-4 is an alternative to PSR-0 that corrects problems discovered in real-world use.

Specification link:

Code and test samples:

308 questions
265
votes
5 answers

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

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. However, I can't seem to grasp what the actual difference is between PSR-0 and…
Varun Nath
  • 5,570
  • 3
  • 23
  • 39
106
votes
3 answers

A non-empty PSR-4 prefix must end with a namespace separator

I'm trying to setup PSR-4 with Composer but I'm just getting A non-empty PSR-4 prefix must end with a namespace separator. My autoload in my composer.json looks like this: "autoload": { "psr-4": { "Acme\\models" : "app/models" …
Marwelln
  • 28,492
  • 21
  • 93
  • 117
58
votes
1 answer

class does not comply with psr-4 autoloading standard. Skipping

I try to use composer autoload but I get this error composer.json { "autoload":{ "psr-4":{ "App\\":"app/" }, "files": ["app/functions/helper.php"] }, "require": { "vlucas/phpdotenv": "^2.4", …
Ahmed Balti
  • 581
  • 1
  • 4
  • 3
38
votes
1 answer

Difference between PSR-4 and classmap autoloading?

In regards to Laravel, I got a question about Composer autoloading i.e. the difference between "psr-4" and "classmap" autoloading. 1 difference that I know is PSR-4 does not need repeated dumpautoload for every changes or addition of new files…
RoMo
  • 413
  • 1
  • 6
  • 10
32
votes
7 answers

Why use a PSR-0 or PSR-4 autoload in composer if classmap is actually faster?

I understand that you can use either a PSR standard to locate files, or tell composer a directory to scan for classes. The documentation recommends using the PSR-4 standard. There is also an option for composer to create an optimized autoloader,…
Bryan Agee
  • 4,924
  • 3
  • 26
  • 42
23
votes
1 answer

Is it possible use multiple classes under the same namespace, in the same file

Is it possible use multiple classes under the same namespace, in the same file? I want to do something like this:
Gligor Florin
  • 380
  • 1
  • 2
  • 12
20
votes
1 answer

PSR-4 autoloader Fatal error: Class not found

I have my project structure like so: src/ ├─ Model/ └─ User.php My User.php file looks like this:
JeremyKirkham
  • 1,025
  • 2
  • 11
  • 22
20
votes
1 answer

PSR-4 autoloading with Composer

I run a portail with composer's autoloading class system: "autoload": { "psr-4": { "Portal\\": "src/" } } It works when I run composer.phar dump -o, for instance my class Boostrap is well referenced into…
Fractaliste
  • 5,777
  • 11
  • 42
  • 86
17
votes
1 answer

How to create a PSR-4 autoloader for my project?

I am creating a PHP project and want to implement PSR-4 autoloading. I don't know which files I need to create in the vendor directory to implement autoloading for class files.
Kshitij Verma
  • 617
  • 1
  • 4
  • 12
16
votes
5 answers

Laravel error 'ReflectionException' - 'Class App\Http\Kernel does not exist'

I was trying to go live with a laravel project i developped a year back in school and i ran into some issue. After uploading the whole project on my hosting service's server, i got these errors on my browser as well as on my SSH shell. Fatal error:…
NicoSalvadore
  • 163
  • 1
  • 2
  • 7
13
votes
1 answer

Composer with PSR-4 autoloading: classes from namespace not loading

I have the follow project structure: - root |- src <- Application specifc source |- [...] |- tests |- [...] |- Vendor |- myusername <- shared packages for all projects |- src |- MyNamespace |- File.php |- autoload.php |-…
Gabriel Santos
  • 4,934
  • 2
  • 43
  • 74
12
votes
1 answer

How does PSR-4 autoloading work in composer for custom libraries?

I use the following directory structure based on my understanding of how namespaces in PHP work: project_root app/ | lib/ | | MyCompany/ | | | Utility/ | | | | Logger.php | | | Core/ …
Scot Calvin
  • 292
  • 4
  • 14
11
votes
2 answers

Using classes without namespace with Yii2

I want to use Checkout SDK with Yii2 but since this library does not support PSR-4 standards (namespaces) I am having trouble to integrate it. How can I use this library for my purpose? EDIT As suggested I tried to use class as $sale = new…
alwaysLearn
  • 6,882
  • 7
  • 39
  • 67
10
votes
2 answers

composer phpunit psr-4 autoload class not found

I am giving composer autoload a try with some phpunit testing classes, and I can't seem to get it to work. When I run phpunit from the command line, I get the following error : "PHP Fatal Error: Class ... not found". I will give all the structure…
Finglish
  • 9,692
  • 14
  • 70
  • 114
9
votes
2 answers

Laravel psr-4 not autoloading

I have a Laravel project that works fine locally (Mavericks), but classes under psr-4 aren't loading on our stage server (CentOS). I'm getting a Reflection "class not found" error every time I try composer update, or run an artisan command. All my…
Heather Gaye
  • 1,118
  • 1
  • 11
  • 19
1
2 3
20 21