|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-12-17 01:08 UTC] scott dot vivian at gmail dot com
Description:
------------
If the __autoload function is declared in a branch that never gets executed, PHP still outputs a deprecation notice. The notice is a little haphazard and mostly only appears the first time a page is loaded. Subsequent refreshes don't show the notice until a restart.
Also, it doesn't occur if you run the script below directly, only if you include it from another script (i.e. autoload.php contains the code below, and test.php includes autoload.php).
Test script:
---------------
<?php
if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
// use spl_autoload_register()
} else {
function __autoload($classname)
{
echo 'called autoloader';
}
}
Expected result:
----------------
No deprecation notice on PHP 7.2, because the else clause doesn't run and so the function is not defined.
Actual result:
--------------
Deprecated: __autoload() is deprecated, use spl_autoload_register() instead in /path/autoload.php on line 6
Appears the first time the page is viewed, disappears after that.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 21:00:01 2026 UTC |
why don't you just fix the code? spl_autoload_register('global_inc_autoloader'); function global_inc_autoloader($class_name){} guess what: before the function was called __autoload() http://php.net/manual/en/function.spl-autoload-register.php (PHP 5 >= 5.1.2, PHP 7) the whole code mess is not needed at all