php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75699 Conditional __autoload declaration always causes deprecation notice
Submitted: 2017-12-17 01:08 UTC Modified: 2017-12-17 13:03 UTC
From: scott dot vivian at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.2.0 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: scott dot vivian at gmail dot com
New email:
PHP Version: OS:

 

 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-17 01:17 UTC] 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:41 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-12-17 01:41 UTC] requinix@php.net
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.
 [2017-12-17 13:03 UTC] scott dot vivian at gmail dot com
> why don't you just fix the code?

Firstly, it’s not my code. It’s actually from PHPMailer but the version that removes __autoload does not support PHP 5.4. (And yes I know 5.4 isn’t supported either but I don’t dictate what other people use.)

Secondly, that’s not even the point. I was reporting something that I thought was incorrect behaviour.

> This is intentional.

OK, thanks for the explanation.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC