I tried to load a utility class to my main class with a namespace but everytime I try to run it it seems to not be working as in not finding the class. The error I got is:
Array
(
[0] => C:\xampp\htdocs\ProjectPapa\assets\php\Classes\Verification.php
[1] => C:\xampp\htdocs\ProjectPapa\assets\php\autoload.php
)
PHP Fatal error: Uncaught Error: Class "Verification\VerificationUtility" not found in C:\xampp\htdocs\ProjectPapa\assets\php\Classes\Verification.php:7
Stack trace:
#0 {main}
thrown in C:\xampp\htdocs\ProjectPapa\assets\php\Classes\Verification.php on line 7
Fatal error: Uncaught Error: Class "Verification\VerificationUtility" not found in C:\xampp\htdocs\ProjectPapa\assets\php\Classes\Verification.php:7
Stack trace:
#0 {main}
thrown in C:\xampp\htdocs\ProjectPapa\assets\php\Classes\Verification.php on line 7
The first array is for me to check what files is included using the get_included_file() function and I have loaded my autoload.php file which loads the rest of my utility classes. This is my code that throws the error above:
<?php
namespace Verification;
include dirname(__DIR__) . "\\autoload.php";
use Verification\VerificationUtility as utility;
echo (new utility())->test();
print_r(get_included_files());
and my autoload.php file:
<?php
foreach (glob("Classes/*Utility.php") as $filename)
{
include_once $filename;
}
print_r(get_included_files());
I tried searching online but I cannot find a solution. I tried php namespace Class not found or PHP namespace confusion, class not found
I made changes and double checked my code, I am including the utility class from autoload.php as this is the output of autoload.php
$ php autoload.php
Array
(
[0] => C:\xampp\htdocs\ProjectPapa\assets\php\autoload.php
[1] => C:\xampp\htdocs\ProjectPapa\assets\php\Classes\VerificationUtility.php
)
Is my autoloading somehow wrong? Thanks for any help in advance.
Edit: I tried to include the file only without the autoload and it is working just fine. However I would like to use the autoloader because if my classes start expanding it would be a pain to include every single file.