PHP script can't work with autoloaded classes

2020-02-15 php autoloader

The UsersView class object can't be loaded with the custom autoloader, finishing the PHP script with the following error. What would be the solution?

Fatal error: Uncaught Error: Class 'UsersView' not found in /Applications/XAMPP/xamppfiles/htdocs/solent/common/registration/pendings.php:4 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/solent/common/registration/pendings.php on line 4

Project structure:

classes
   |_____ UsersView.php

common
   |_____ autoloader.php
   |_____ registration
               |_____ pendings.php

Pendings.php script

include("../autoloader.php");

$pendingsView = new UsersView();
$rows = $pendingsView->getAllUsers();

Autoloader.php script

spl_autoload_register('myAutoLoader');

    function myAutoLoader($className) {
        $path = "../classes";
        $extension = ".php";

        $fullPath = $path . $className . $extension;

        if(!file_exists($fullPath)) {
            return false;
        }

    include_once $fullPath;

Answers

Related