php spl_autoload_register vs __autoload?

后端 未结 2 1498
轻奢々
轻奢々 2020-12-05 02:19

hello is there any diffrence useing this excepts that we can use our own name auto load? is there any performance difference? how do they internally work?

between

2条回答
  •  青春惊慌失措
    2020-12-05 03:06

    __autoload is generally considered obsolete. It only allows for a single autoloader. Generally you should only use __autoload if you're using a version of PHP without support for spl_autload_register.

    spl_autoload_register allows several autoloaders to be registered which will be run through in turn until a matching class/interface/trait is found and loaded, or until all autoloading options have been exhausted. This means that if you're using framework code or other third party libraries that implement their own autoloaders you don't have to worry about yours causing conflicts.

    UPDATE:

    __autoload is now officially deprecated as of PHP 7.2.0, which means it's now on the chopping block. If you want your code to be compatible with future versions of PHP you definitely should not use __autoload

提交回复
热议问题