Class loading order affects E_STRICT warning.
| 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 commits