Bug #75699 [Com]: Conditional __autoload declaration always causes deprecation notice

From: Date: Sun, 17 Dec 2017 01:17:55 +0000
Subject: Bug #75699 [Com]: Conditional __autoload declaration always causes deprecation notice
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213143@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75699&edit=1

 ID:                 75699
 Comment by:         spam2 at rhsoft dot net
 Reported by:        scott dot vivian at gmail dot com
 Summary:            Conditional __autoload declaration always causes
                     deprecation notice
 Status:             Open
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Ubuntu
 PHP Version:        7.2.0
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[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)

« previous php.bugs (#213143) next »