​Hi php internals,

Currently spl_autoload_register() pass the name of the class entity to the
first *Callable* argument​, but there is now way (as i far i know) to know
what kind of entity we're looking for.
-Class ?
-Interface ?
-Trait?


A second argument should be added to the *Callable* function describing
what kind of entity we're looking for.

Example:

<?php

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

function my_autoloader($entity, $kind = "class") {
   // Kind would be: class/interface/trait
   include $kind . '/' . $entity . ".{$kind}.php";
}

spl_autoload_register('my_autoloader');

// Or, using an anonymous function as of PHP 5.3.0
spl_autoload_register(function ($entity, $kind = "class") {
   // Kind would be: class/interface/trait
   include $kind . '/' . $entity . ".{$kind}.php";
});

?>


In fact i think currently that Autoload is too much "class oriented" as per
reading php docs, whereas that php currently allow the autoload of many
entities. It can really confuse probies php developers :(

*Pros*:

   - -Avoid multiple else if() for testing an existing file to load the
   entity.
   - -As we now know the type of entity to load, it help reduce I/O
   activity, then reduce  timespend.
   - -Clarify the code: We now  what the autoloader will load
   - -Keep the BC safe


*Cons*:

   - -None



Regards,
Georges.L

Reply via email to