I am new to autoloading in PHP and have a requirement for Horde_Text_Diff in my latest project. I am using Horde_Autoloader to autoload the required files, however, I am not using it correctly. As far as I can Google, there is not a single example of how to actually do it that exists on the internet. I pretty much learn 100% from example and so I have hit a roadblock here.
This is what I have so far ...
require_once( Horder/Autoloader.php );
$autoloader = new Horde_Autoloader();
No problem so far, the object is created ...
$text_diff = $autoloader->loadClass( 'Hoard_Text_Diff' );
This is not working as I am purely guessing here.
What lead me to where I am was this post.
I've looked at the source code at https://github.com/dereuromark/tools/tree/master/Vendor/Horde.
The
Horde_Autoloader
does not have a mapper attached and you're using it wrong. The autoloader needs a classPathMapper added. There are different classPathMappers in theHorde / Autoloader / ClassPathMapper
directory.There is also a default autoloader which registers all paths from your include_path automatically. This can be a little overhead!
EDIT:
It works for me. The following code is in
C:\xampp\htdocs\horde\index.php
. The horde lib is in subfolderlib
.