I am using PHP 7.3.5 and I have two files, class Foo(), which is in the directory ./db/models and my main.php, which is in the root of the project.
<?php
use Goutte\Client;
class Foo
{
function getHello()
{
echo "Hello world!<br>";
}
}
My main.php file looks the following:
<?php
include("./db/models/Foo.php");
$foo = new Foo;
$foo->getHello();
However, I get the following error:
PHP Fatal error: Uncaught Error: Class 'Foo' not found in C:\Users\Desktop\Code\test-project\main.php:5
Any suggestions what I am doing wrong?
Foo.php-file?__DIR__to get the absolute path to the file you're in. If just doinclude 'db/...';it will load the file relative from the top most file (usually the index.php file). Check out this answer that explains it in more detail.error_reporting(E_ALL);while you develop so you make sure you see all warnings as well. The error reporting level can also be set in your php.ini-file.