1.2.870. Old Style __autoload()

Avoid __autoload(), only use spl_register_autoload().

__autoload() is deprecated since PHP 7.2 and possibly removed in later versions. spl_register_autoload() was introduced in PHP 5.1.0.

__autoload() may only be declared once, and cannot be modified later. This creates potential conflicts between libraries that try to set up their own autoloading schema.

On the other hand, spl_register_autoload() allows registering and unregistering multiple autoloading functions or methods.

Do not use the old __autoload() function, but rather the new spl_register_autoload() function.

<?php

// Modern autoloading.
function myAutoload($class){}
spl_register_autoload('myAutoload');

// Old style autoloading.
function __autoload($class){}

?>

See also Autoloading Classes.

1.2.870.1. Suggestions

  • Move to spl_register_autoload()

  • Remove usage of the old __autoload() function

  • Modernize usage of old libraries

1.2.870.2. Specs

Short name

Php/oldAutoloadUsage

Rulesets

All, Analyze

Exakat since

0.8.4

PHP Version

All

Severity

Major

Time To Fix

Instant (5 mins)

Precision

Very high

Features

autoload

ClearPHP

use-smart-autoload

Examples

Piwigo

Available in

Entreprise Edition, Exakat Cloud