0

I'm learning the composer for a first time with downloading geo-package 'menarasolutions/geographer'. I used to follow package docks but recieve an error:

Fatal error: Uncaught Error: Class "MenaraSolutions\Geographer\Earth" not found in
PATH/fresh-air-2/index.php:7 Stack trace: #0 {main} thrown in
PATH/fresh-air-2/index.php on line 7

composer.json

{
    "require": {
        "menarasolutions/geographer": "^0.3.13"
    }
}

And that's it my code:

<?php

use MenaraSolutions\Geographer\Earth;
use MenaraSolutions\Geographer\Country;

// Default entry point is our beautiful planet
$earth = new Earth();

// Give me a list of all countries please
print_r($earth->getCountries()->toArray());

Also there is my project files tree: enter image description here

I tried to require_once '/vendor/autoload.php'; but I think server doesn't see this folder in project. Error looks like

Warning: require_once(/vendor/autoload.php): Failed to open stream: No such file or directory in PATH/fresh-air-2/index.php on line 3
Vadym
  • 11
  • 2
  • 1
    `require_once(/vendor/autoload.php)` - The initial `/` in front of the path means that it will be looking for `vendor` in the root of the file system. Make sure the path to `autoload.php` is correct. And you need to include that file to handle autoloading, or include all needed classes manually, before you can use them. – M. Eriksson Mar 29 '23 at 11:09
  • 1
    You were on the right lines with needing to include `autoload.php`, but you need to understand how to specify the right path for that file. For that, you can read up on [the two different things that you might want it to be relative to](https://stackoverflow.com/questions/7378814/are-php-include-paths-relative-to-the-file-or-the-calling-code). Always using `___DIR__`, because is probably the easiest to understand. – IMSoP Mar 29 '23 at 11:22
  • Thank you, guys, so much - it works and I have learned something new because of your advices. – Vadym Mar 29 '23 at 11:27

0 Answers0