请输入您要查询的百科知识:

 

词条 Autoload
释义

  1. PHP

  2. External links

{{Other uses|Autoloader (disambiguation)}}{{Expert-subject|reason=This looks like original research|date=September 2014}}

In computer programming, autoloading is the capability of loading and linking portions of a program from mass storage automatically when needed, so that the programmer is not required to define or include those portions of the program explicitly. Many high-level programming languages include autoload capabilities, which sacrifice some run-time speed for ease of coding and speed of initial compilation/linking.

Typical autoload systems intercept procedure calls to undefined subroutines. The autoloader searches through a path of directories in the computer's file system, to find a file containing source or object code that defines the subroutine. The autoloader then loads and links the file, and hands control back to the main program so that the subroutine gets executed as if it had already been defined and linked before the call.

Many interactive and high-level languages operate in this way. For example, IDL includes a primitive path searcher, and Perl allows individual modules to determine how and whether autoloading should occur. The Unix shell may be said to consist almost entirely of an autoloader (program), as its main job is to search a path of directories to load and execute command files. In PHP 5, autoload functionality is triggered when referencing an undefined class. One or more autoload functions—implemented as the __autoload magic function or any function registered to the SPL autoload stack—is called and given the opportunity to define the class, usually by loading the file it is defined in.

PHP

spl_autoload_register(function ($class) {

    $file = 'src/' . str_replace('\\\\', '/', $relative_class) . '.php';    if (file_exists($file)) {        require $file;    }

});

External links

  • PSR-4 Improved Autoloading Standard
  • Autoloading Classes in PHP
  • spl_autoload_register in PHP
{{Unreferenced|date=December 2007}}

1 : Programming constructs

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/29 15:22:25