As discussed in the comments, seeking to better understand the problem, the lack of file loading autoload
Composer makes PHP not know how to find the classes. Composer does magic, but not so much. After installation, there must be a directory vendor
in your application, with the project dependencies. Before using them, insert the file autoload
, at the beginning of each file:
<?php
require __DIR__ . '/vendor/autoload.php';
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\FirePHPHandler;
// Create the logger
$logger = new Logger('my_logger');
The archive vendor/autoload.php
is the Composer standard, which makes all the magic happen.
Note: the file autoload
should be included once for each request handled in PHP. That is, if your application requests several PHP files, the require autoload
must be present in all of them. If it is based on some architecture, such as MVC, where all requests are handled in just one file, just put in it to be accessible throughout the project.
Using Composer or some other autoload tool?
– Woss
@Andersoncarloswoss I use Composer
– Jonathan
And the autoload file was inserted into the project at some point?
– Woss
@Andersoncarloswoss Yes, it’s inside the 'Vendor' folder'
– Jonathan
Inserted in order to give
include
orrequire
in this file. Excuse me if you know how to use Composer and these questions seem basic, but is that the error seems to be in PHP can not load the class and the absence ofinclude
would make perfect sense.– Woss
It may be that the basic help me, because I don’t use much php, so I don’t know much. No, the autoload file was not loaded, I figured that only use the
use Monolog\Logger;
was enough to make it work– Jonathan
Now it worked. Put an answer telling me to perform a require on autoload. @Andersoncarloswoss
– Jonathan