note 80670 deleted from language.oop5.autoload by crell
| From: | crell@php.net | Date: | Mon, 04 Apr 2022 16:09:02 +0000 |
| Subject: | note 80670 deleted from language.oop5.autoload by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218022@lists.php.net to get a copy of this message | ||
Note Submitter: muratyaman at gmail dot com
----
__autoload() function can be very useful to optimize your code esp. when you have so many classes.
Unlike class extensions, optional parameters with class restrictions may not load your class.
<?php
class bClass{
function fun($p1, aClass $p2=NULL){
//do something
}
}
//depending on the usage
$b = new bClass();
$b->fun('No!');//this will not load class file for aClass
$b->fun('Really?', new aClass('Yes!'));//this will
?>
So, it's very encouraging to use classes everywhere!
Even encapsulating your functions inside simple classes to use like static modules, will help a lot!
Let's say, you have <b>50k</b> lines of code inside <b>100</b>
classes/files.. If you need a simple task to do very quickly, you should not be loading all of those
files, except the ones you need.
Though, it may be dangerous on some cases regarding the dependencies, load order, etc. Carefully
design your classes.