- Modernizing Legacy Applications in PHP
- Paul M. Jones
- 171字
- 2021-07-14 10:07:02
Using The __autoload() Function
If we are stuck on PHP 5.0 for some reason, we can use the __autoload()
function in place of the SPL autoloader registry. There are drawbacks to doing things this way, but under PHP 5.0 it is our only alternative. We do not need to register it with SPL (in fact, we cannot, since SPL was not introduced until PHP 5.1). We will not be able to mix-and-match other autoloaders in this implementation; only one __autoload()
function is allowed. If an __autoload()
function is already defined, we will need to merge this code with any code already existing in the function:
setup.php
1 <?php
2 // ... setup code ...
3
4 // define an __autoload() function
5 function __autoload($class)
6 {
7 // ... the global function code ...
8 }
9
10 // ... other setup code ...
11 ?>
I strongly recommend against using this kind of implementation in PHP 5.1 and later.
Autoloader Priority
Regardless of how we implement our autoloader code, we need it to be available before any classes get called in the codebase. It cannot hurt to register the autoloader as one of the very first bits of logic in our codebase, probably in a setup or bootstrap script.
- 計(jì)算機(jī)網(wǎng)絡(luò)
- Cocos2D-X權(quán)威指南(第2版)
- PyQt從入門到精通
- 云原生Spring實(shí)戰(zhàn)
- HTML5游戲開發(fā)案例教程
- The DevOps 2.4 Toolkit
- Microsoft System Center Orchestrator 2012 R2 Essentials
- SQL 經(jīng)典實(shí)例
- Visual Studio 2015高級(jí)編程(第6版)
- Kubernetes源碼剖析
- 移動(dòng)增值應(yīng)用開發(fā)技術(shù)導(dǎo)論
- Laravel Application Development Blueprints
- Windows Phone 8 Game Development
- Flink技術(shù)內(nèi)幕:架構(gòu)設(shè)計(jì)與實(shí)現(xiàn)原理
- Microsoft Exchange Server 2016 PowerShell Cookbook(Fourth Edition)