Questions tagged [psr-0]

PSR-0 describes requirements that must be adhered to for autoloader interoperability in PHP.

PSR

Proposing a Standards Recommendation.

PSR-0 Aims to provide a standard file, class and namespace convention to allow plug-and-play code.

PSR-1 Aims to ensure a high level of technical interoperability between shared code.

PSR-2 Provides a Coding Style Guide for projects looking to standardise their code.


Resources

120 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
67
votes
2 answers

Composer/PSR - How to autoload functions?

How can I autoload helper functions (outside of any class)? Can I specify in composer.json some kind of bootstrap file that should be loaded first?
mpen
  • 272,448
  • 266
  • 850
  • 1,236
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
19
votes
7 answers

PHP - most lightweight psr-0 compliant autoloader

I have a tiny application that i need an autoloader for. I could easily use the symfony2 class loader but it seems like overkill. Is there a stable extremely lightweight psr-0 autloader out there?
Marty Wallace
  • 34,046
  • 53
  • 137
  • 200
14
votes
1 answer

How to use a PHP library with namespacing without Composer as dependency (PSR-0)?

I need to use some PHP libraries with dependencies but I have some restrictions on the webserver of the client. It is a managed webserver and I can not use a console eg over SSH. So how do I use now these libraries without Composer? Can I create…
user753676
14
votes
1 answer

composer autoloader psr-0 namespaces

I have create a custom composer package but I am having troubles to set the correct autoload options for it. All my classes are under MyNamespace/Common namespace. So for example for including my ArrayHelper class I do use…
brpaz
  • 3,618
  • 9
  • 48
  • 75
13
votes
3 answers

Composer Not Generating Autoloads For Library

I've set up two projects, an 'init' and a library, which is required by the init. They both have PSR-0 autoloads set, but the autoload values from the library are not added to the vendor/composer/autoload_namespaces.php in the init project. Sample…
bmcgavin
  • 203
  • 1
  • 3
  • 7
10
votes
5 answers

Composer Autoloading

I'm currently trying to use PSR-0 autoloading with Composer, but I'm getting the following error: Fatal error: Class 'Twitter\Twitter' not found My directory structure looks like this - Project - src - Twitter Twitter.php …
James Jeffery
  • 12,093
  • 19
  • 74
  • 108
8
votes
2 answers

If PHP libraries can register their own autoloaders, then why does PSR-0 require they be in uniform directories?

I'm building a framework (this is a vast simplification -- please don't recommend using an existing framework instead, that's not helpful) into which I would like to be able to integrate other libraries. The PSR-0 recommendation suggests that all…
ringmaster
  • 2,879
  • 3
  • 28
  • 31
7
votes
2 answers

Composer is not loading my own psr-0 files

I can't seem to get composer to work with my own classes/files using the psr-0 autoload mechanism. Can anyone please shed some light as to why the below isn't working? I'm getting the following output in my error log: PHP Fatal error: Class…
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
6
votes
3 answers

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

The PSR-0 (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) standard specifies that an underscore in the class name should be converted to a directory separator in the corresponding file name. To me this does not seem to be a…
Carlos Granados
  • 11,273
  • 1
  • 38
  • 44
5
votes
1 answer

Eclipse - Using File Name Conventions on Refactoring php-Classes

I am new to eclipse and am using version Version: Mars.1 Release (4.5.1) I am using the refactoring tool of the "PHP Development Tools 3.6" plugin to rename e.g. classes. Our class file names follow the simple PSR-0 convention that an underscore…
Ben
  • 51
  • 3
5
votes
1 answer

Composer - Autoload and PSR-0 vs PSR-4

I'm beginning to study Composer and am developing a system where I separate the files core application files, as follows: /root |-- /src |-- /App |-- /DBConfig |-- /Controller |--…
LeoFelipe
  • 281
  • 6
  • 13
5
votes
1 answer

Does PHP's use statement cause extra work when loading classes?

Code Sample 1 use Outline\Drawing; $var = new Drawing(); Code Sample 2 $var = new Outline\Drawing(); Question: Does PHP make hardware work harder (look up more files or do more processing) if I use code in sample 1? I am sure something gets done,…
Dennis
  • 7,907
  • 11
  • 65
  • 115
5
votes
1 answer

Can't generate entities after psr-0 to psr-4 change

I changed the psr-0 autoloading to psr-4 for a few of my bundles. Now, when I try to generate entities with the app/console command, it gives me Can't find base path for "MbDbFooBundle" (path: …
rolandow
  • 1,049
  • 1
  • 15
  • 28
1
2 3 4 5 6 7 8