Add new comment

Yeah, once you instantiate an object, and use the class, the file is parsed, and it's loaded into memory. There's no way around that. The benefit with using autoloading, like PSR-4, is that files are only read into memory if the class is actually used during the request.

By comparison, non-autoloading implies that you have to load every single class into memory even if you never use it, just so you can make sure it's available when you do try and use it. Consider the following code:


if ($i == 'some condition') {
$ClassOnlyUsedHere = new SomeClass();
$ClassOnlyUsedHere->doSomething();
}
else {
$Class = new OtherClass();
$Class->doSomethingElse();
}

In this case you've got classes that are only used if the some conditional logic in the application is met. Your options here are either autoloading at the time of use, or load all classes during bootsrap just in-case you need SomeClass. In the later the code that composes SomeClass is parsed and loaded into memory even if it's not used.

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <code class> <ul type> <ol start type> <li> <dl> <dt> <dd><h3 id> <p>
  • Lines and paragraphs break automatically.