Bug #75699 [Opn->Nab]: Conditional __autoload declaration always causes deprecation notice
Edit report at https://bugs.php.net/bug.php?id=75699&edit=1
ID: 75699
Updated by: requinix@php.net
Reported by: scott dot vivian at gmail dot com
Summary: Conditional __autoload declaration always causes
deprecation notice
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Ubuntu
PHP Version: 7.2.0
Block user comment: N
Private report: N
New Comment:
This is intentional. The deprecation notice is raised during the compilation phase, not execution;
with an opcache you will only see it the first time the file is loaded.
https://wiki.php.net/rfc/deprecations_php_7_2#autoload
Note that PHP 5.1.2 was released nearly 12 years ago and the 5.1 series was out of support a few
months later.
> Also, it doesn't occur if you run the script below directly,
My tests show the notice in all cases - directly, inline (php -r), and include()d.
Previous Comments:
------------------------------------------------------------------------
[2017-12-17 01:17:54] spam2 at rhsoft dot net
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
------------------------------------------------------------------------
[2017-12-17 01:08:49] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75699&edit=1
Thread (4 messages)