I am trying to define my PHP __autoload function as bulletproof and flexible as possible.
Here is a breakdown of my application structure:
/dev (root)
/my_app
/php
/classes
- Class1.php
- Class2.php
- Class3.php
/scripts
myscript.php (the file I have to include the classes in)
This is pretty straight forward. My problem is this: how to write my __autoload function so that I can include any class I want, no matter how deep the nested calling file is in the directory structure. I know that this has something to do with the functions __FILE__, realpathand dirname, but I'm not sure that they can be combined to achieve the flexibility that I use.
Here is a quick test I did:
<?php
echo realpath(dirname(__FILE__)) . "/php/classes/Class1.php";
?>
Result:
/home/mydirectory/dev.mysite.com/my_app/php/scripts/php/classes/Class1.php
, , . , myscript.php /my _app, .
?