Question: I am planning to use PHP's autoload function to dynamicly load only class files that are needed. Now this could create a huge mess if every single function has a seperate file, So I am hoping and asking is there a way to have related classes remain in 1 class file and still be auto-loaded

```
function __autoload($class_name){
    include('classes/' . $class_name . '.class.php');
}

```

Let's say there is a class name animals and then another class named dogs. Dogs class extends animals class, now if I were to call the dogs class but NOT call the animals class, would the animals class file still be loaded?

Answer: 
> 
> if I were to call the dogs class but
>  NOT call the animals class, would the
>  animals class file still be loaded?
> 
> 
> 

Yes. When you load an class that extends another class, PHP must load the base class so it knows what it's extending.

re: the idea of storing multiple classes per file: This will not work with the autoload function you provided. One class per file is really the best practice, especially for autoloaded classes.

If you have more than one class in a file, you really shouldn't attempt to autoload any classes from that file.
There's a workaround, I've just used it and it seems to work:

Let's assume we have an autoloaded class called animals stored in animals.class.php. In the same file you could have other classes that extends animals 

```
    class animals{
        static function load(){
            return true;
        }
    }

    class dogs extends animals{

    }

    class cats extends animals{

    }

```

Now... when you need to use your class `dogs` you need PHP autoload it's parent class (and doing this you're sure it will parse also all the extendend classes inside the same file) so you just have to write:

```
animals::load();
$fuffy = new dogs();

```