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

Friday, January 21, 2022

[FIXED] How I use composer autoloading?

 January 21, 2022     composer-php     No comments   

Issue

I have such project https://github.com/prazny/composer-autoload

What am I doing wrong?
I would like to load class 'Writing' to composer.
index.php: Fatal error: Class 'MyApp\Writing\Writing' not found in C:\xampp\htdocs\kurs\composer-autoload\index.php on line 4


Solution

You have several issues:

  1. Problem: Class/File name mismatch. Solution: Rename ./src/Writing/Write.php to ./src/Writing/Writing.php
  2. Problem: PSR-4 autoloading standard compliance Solution: Change your PSR-4 config from "": "src/Writing/Write.php" to "MyApp\\": "src/"
  3. Then regenerate your autoload file by running composer dumpautoload

Once you do all that, you'll get a fatal error in your index.php because you're trying to echo an instance of an object that does not have a __toString. This will tell you autoloading is working and that you need to fix your index.php code.

Also, you shouldn't commit the vendor directory. That, however, is an aside and is not causing the issues you're having.



Answered By - JAAulde
  • 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