php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64988 Class loading order affects E_STRICT warning.
Submitted: 2013-06-07 14:37 UTC Modified: -
From: RQuadling at GMail dot com Assigned:
Status: Closed Package: *General Issues
PHP Version: 5.4.16 OS: Centos
Private report: No CVE-ID: None
 [2013-06-07 14:37 UTC] RQuadling at GMail dot com
Description:
------------
The load/compile order seems to affect the E_STRICT warning PHP Strict Standards:  
Declaration of class::method() should be compatible with class::method(array 
$data).

The attached script simulates an autoloader to load three classes in the expected 
order for an autoloader (i.e. smooth1 => noisy1 => base1) as well as second set 
suitable for a non autoloader environment (i.e. base2, noisy2, smooth2).

I only get the E_STRICT warning on the autoloaded loaded classes.

Test script:
---------------
<?php
error_reporting(-1);
function __autoload($s_Class) {
    switch ($s_Class) {
        case 'Smooth1' :
            class Smooth1 extends Noisy1 {
                public function insert(array $data) {
                    return parent::insert($data, count($data));
                }
            }
            break;
        case 'Noisy1' :
            class Noisy1 extends Base1 {
                public function insert(array $data, $option1 = Null) {
                    if (!empty($option1)) {
                        $data['option1'] = $option1;
                    }
                    return parent::insert($data);
                }
            }
            break;
        case 'Base1' :
            abstract class Base1 {
                public function insert(array $data){
                    return array_reverse($data);
                }
            }
            break;
    }
}
abstract class Base2 {
    public function insert(array $data) {
        return array_reverse($data);
    }
}

class Noisy2 extends Base2 {
    public function insert(array $data, $option1 = Null) {
        if (!empty($option1)) {
            $data['option1'] = $option1;
        }
        return parent::insert($data);
    }
}

class Smooth2 extends Noisy2 {
    public function insert(array $data) {
        return parent::insert($data, count($data));
    }
}

$o = new Smooth1();
print_r($o->insert(array('a', 'b', 'c')));
$o = new Smooth2();
print_r($o->insert(array('a', 'b', 'c')));
$o = new Smooth1();
print_r($o->insert(array('a', 'b', 'c')));
$o = new Smooth2();
print_r($o->insert(array('a', 'b', 'c')));


Expected result:
----------------
Array
(
    [option1] => 3
    [0] => c
    [1] => b
    [2] => a
)
Array
(
    [option1] => 3
    [0] => c
    [1] => b
    [2] => a
)
Array
(
    [option1] => 3
    [0] => c
    [1] => b
    [2] => a
)
Array
(
    [option1] => 3
    [0] => c
    [1] => b
    [2] => a
)


Actual result:
--------------
PHP Strict Standards:  Declaration of Smooth1::insert() should be compatible 
with Base1::insert(array $data) in - on line 6

Strict Standards: Declaration of Smooth1::insert() should be compatible with 
Base1::insert(array $data) in - on line 6
Array
(
    [option1] => 3
    [0] => c
    [1] => b
    [2] => a
)
Array
(
    [option1] => 3
    [0] => c
    [1] => b
    [2] => a
)
Array
(
    [option1] => 3
    [0] => c
    [1] => b
    [2] => a
)
Array
(
    [option1] => 3
    [0] => c
    [1] => b
    [2] => a
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-10 13:36 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d8792d87cf978ef2a977362a7ef8f357820867c2
Log: Fixed bug #64988 (Class loading order affects E_STRICT warning)
 [2013-06-10 13:36 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2014-10-07 23:18 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=d8792d87cf978ef2a977362a7ef8f357820867c2
Log: Fixed bug #64988 (Class loading order affects E_STRICT warning)
 [2014-10-07 23:30 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=d8792d87cf978ef2a977362a7ef8f357820867c2
Log: Fixed bug #64988 (Class loading order affects E_STRICT warning)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC