Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That's a confusing name for the file, as autoloading is a mechanism in PHP that allows you to load classes as and when they are needed, a good solution when you have many classes and only a few will be needed for each execution.</p> <p>For example:</p> <pre><code>function autoload($class_name) { $file = "classes/$class_name.php"; // You could add some checks here (e.g. whether the file exists, whether the // class indeed exists after the file is loaded) to facilitate better errors, // of course this would marginally increase the time needed to load each class. require $file; } // Register the `autoload` function with PHP's autoload mechanism spl_autoload_register('autoload'); // This will execute `autoload('Class')` (unless `Class` is already defined) $instance = new Class; </code></pre> <p>So, to answer your questions:</p> <ol> <li><p>It is not necessary to load them all, however classes that are used must be available, either by loading them all together (current situation), loading them conditionally (<code>if(p == 'whatever') require 'classes/whatever.php'</code>), or by using autoloading.</p></li> <li><p>There is some delay whenever a file is included as the file must be parsed/executed. PHP is fairly fast but still, including files you do not need is a waste. If you're using bytecode caching, the retrieved bytecode must still be executed.</p></li> <li><p>That is one avenue of improvement, autoloading presents a more dynamic alternative.</p></li> <li><p>Dependencies may be a problem if any of your page classes depend on another class, as your conditional loading could get very bloated.</p></li> </ol> <p>Also a little additional material regarding bytecode caching, if you're using it:</p> <ul> <li><a href="https://stackoverflow.com/questions/1941541/php5-frameworks-autoloading-and-opcode-caching">PHP5 Frameworks: Autoloading and Opcode Caching</a></li> <li><a href="https://stackoverflow.com/questions/1396501/do-php-opcode-cache-work-with-autoload">Do PHP opcode cache work with __autoload?</a></li> </ul> <p>The summary seems to be that, as long as you use <code>include</code> or <code>require</code> to load the file, bytecode caching will work as intended.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload