PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 18, 2022

[FIXED] Why the return value in autoload.php of composer?

 February 18, 2022     autoloader, composer-php     No comments   

Issue

I am focusing on the very short, generated file vendor/autoload.php and its final statement:

return ComposerAutoloaderInitXXXX::getLoader();

Looking at the logic of the code, when executed from an HTTP request, I could not see the need of a return value. I have removed the return in the final statement, only kept

ComposerAutoloaderInitXXXX::getLoader();

and tested with a simple "HELLO WORLD" web application and it worked the same way.

Perhaps that in some other applications of vendor/autoload.php we might need a return value.

What would be an example of such an application?


Solution

From composer's documentation:

Including that file will also return the autoloader instance, so you can store the return value of the include call in a variable and add more namespaces. This can be useful for autoloading classes in a test suite, for example.

$loader = require __DIR__ . '/vendor/autoload.php';
$loader->addPsr4('Acme\\Test\\', __DIR__);


Answered By - Paul
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing