From:             RQuadling at GMail dot com
Operating system: Centos
PHP version:      5.4.16
Package:          *General Issues
Bug Type:         Bug
Bug description:Class loading order affects E_STRICT warning.

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
)


-- 
Edit bug report at https://bugs.php.net/bug.php?id=64988&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64988&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64988&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64988&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64988&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64988&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64988&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64988&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64988&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64988&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64988&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64988&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64988&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64988&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64988&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64988&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64988&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64988&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64988&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64988&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64988&r=mysqlcfg

Reply via email to