官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 阿瓦提县| 方正县| 三台县| 迭部县| 攀枝花市| 祁东县| 长寿区| 民勤县| 钟祥市| 东乌珠穆沁旗| 清镇市| 英吉沙县| 峨边| 安达市| 灵台县| 桃园县| 兴化市| 化德县| 巩义市| 英山县| 淅川县| 喀喇| 怀仁县| 岐山县| 黄大仙区| 鹤峰县| 开封县| 红原县| 汾西县| 连云港市| 海城市| 玉溪市| 永济市| 西平县| 南和县| 黄浦区| 沐川县| 永登县| 鄂尔多斯市| 虎林市| 阳山县|