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?
include("db/models/Foo.php");
Since your db folder is inside route you can simple access it like that.
You don't need the ./ to move one step before cause your main is already in the root. You need to move inside your nested folders to reach the Foo.php
Since you did not provide the full tree i assumed that your path to Foo.php is:
C:\Users\Desktop\Code\test-project\db\models\Foo.php
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments