Since your autoloader does — what its name says — automatically load your classes, you do not need any other requirements other than those in the autoloader function.
If you use require_once instead of require in it, it will still load it only once, regardless of whether you extend it or just create an object.
So just use the code you posted in your question and remove require_once () in your animal.php, since the autoloader already requires it.
Note: if you do not want to create your own autoloader, you can use composer autoloader. It is easy to install and very useful as it deals with subdirectories and forces you to follow a strict namespace convention.
If you want to do this, you must first install the composer. Then you create a file called composer.json in your base directory with the following contents
{ "autoload": { "psr-4": { "YourProject\\": "src/" } } }
Then you need to run the following command on the command line:
cd path/to/your/project composer dump-autoload
If you have done this, put your classes in basedirectory / src. Note that now you need to provide all classes with a namespace, in this case, if there was a namespace YourProject . You are finally done!
Now go to your base directory and create a file, call index.php:
require_once ('vendor/autoloader.php'); $a = new YourProject\Animal();
Sorry for the long note, sir!