AJAX到扩展的PHP类,包含的类不会被传递

I am calling a function via AJAX from a PHP class that extends another class but is not included in that file instead it was included in a different file. To elaborate here's my code:

Client:

$('.username').change(function(){
        var indexOfNumber = $(this).attr('class').indexOf('d');
        var number = $(this).attr('class').substring(Number(indexOfNumber)+1);

        $.ajax({
            url: 'class1.php',
            complete: function(response) {
                alert(response.responseText);
            },
            error: function(){
                alert("error");
            }
        });

        $('.userrole.d'+number).html(number);
    });

Class1:

class class1 extends class2
{
    function class1()
    {
        $this->class2(); << I am getting an error here
    }

The error that I am getting is:

Class 'class2' not found in (location of class1).

class2 is included in the config.php file of the project and thus it's not included again in the files, when I call that file from AJAX it doesn't seem to see the previously included PHP files.

Any way around this?

The only way around it is to require the necessary files in class1.php. Or you could include a file that loads a custom autoloader which can dynamically load files when requesting classes.