spl_autoload_call

(PHP 5 >= 5.1.2)

spl_autoload_call Попытка загрузить описание класса всеми зарегистрированными методами __autoload()

Описание

void spl_autoload_call ( string $class_name )

Эту фунцию можно использовать для ручного поиска описания класса или интерфейса, используя все зарегистрированные реализации метода __autoload.

Список параметров

class_name

Имя искомого класса.

Возвращаемые значения

Эта функция не возвращает значения после выполнения.

Коментарии

It should be noted, that calling spl_autoload_call on a child class, and then on its parent class, throws a fatal error.

This happens because autoloading the child class also loads the class it extends. And since spl_autoload_call forcibly calls the registered autoload function(s), not taking into account whether the class exists, a fatal error is thrown:

File: child.class.php

<?php
class Child extends Parent () {
    public function 
__construct () {
       
parent::__construct();
    }
}
?>

File: parent.class.php

<?php
class Parent () {
    public function 
__construct () {

    }
}
?>

File: autoload.php

<?php

/*    works fine    */
   
spl_autoload_call('Child');

/*    throws: Fatal error: Cannot redeclare class Parent in /parent.class.php on line 2    */
   
spl_autoload_call('Parent');

?>
2011-02-02 05:40:24
http://php5.kiev.ua/manual/ru/function.spl-autoload-call.html
Автор:
A complete example with namespaces:

fruits/pinapple.php

<?php
namespace Fruits;
echo 
"pinapple\n";
class 
Pinapple { }
?>

fruits/pinapple.php

<?php
namespace Vegetables;
use 
Fruits\Pinapple;
echo 
"carrot\n";
class 
Carrot { }
new 
Pinapple(); // Let's call autoload here
?>

index.php

<?php
spl_autoload_register
(function($class_name) {
    @include_once(
__DIR__ '/' strtolower(str_replace('\\''/'$class_name)) . '.php');
});
new 
Vegetables\Carrot();
?>

Result:

carrot
pinapple

index2.php

<?php
spl_autoload_register
(function($class_name) {
    @include_once(
__DIR__ '/' strtolower(str_replace('\\''/'$class_name)) . '.php');
});
spl_autoload_call('Fruits\\Pinapple'); // Reverse the load order
spl_autoload_call('Fruits\\Pinapple'); // Multiple call is safe with include_once
new Vegetables\Carrot();
?>

Result:

pinapple
carrot
2021-04-15 13:23:58
http://php5.kiev.ua/manual/ru/function.spl-autoload-call.html

    Поддержать сайт на родительском проекте КГБ