php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46984 Strict-Warning when overwriting methods with changed parameters
Submitted: 2008-12-31 12:52 UTC Modified: 2009-02-03 19:53 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: d_quijote at web dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.0alpha3 OS: *
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: d_quijote at web dot de
New email:
PHP Version: OS:

 

 [2008-12-31 12:52 UTC] d_quijote at web dot de
Description:
------------
A Strict-Warning is raised when the parameters of the subclass differ from the parameters of the overwritten superclass method. This error seems only to occure if any interface is included in the superclass

Reproduce code:
---------------
class A implements Iterator {
	public function current() {}
	public function key() {}
	public function next() {}
	public function rewind() {}
	public function valid() {}
	
	public function f($x) {
		echo $x.PHP_EOL;
	}
}

class B extends A {
	public function f($x,$y) {
		echo __METHOD__.'('.$x.', '.$y.')'.PHP_EOL;
	}
}

$b = new B();
$b->f(1,2);

Expected result:
----------------
B::f(1, 2)

Actual result:
--------------
Strict Standards: Declaration of B::f() should be compatible with that of A::f() in /index.php on line 19

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-01 00:21 UTC] felipe@php.net
I agree with you, here is a patch:
http://felipe.ath.cx/diff/bug46984.diff

However it broken some tests, that for me, looks as even they are wrong.
method overloading with different method signature [Zend/tests/objects_002.phpt]
method overloading with different method signature [Zend/tests/objects_003.phpt]
method overloading with different method signature [Zend/tests/objects_004.phpt]
method overloading with different method signature [Zend/tests/objects_005.phpt]
method overloading with different method signature [Zend/tests/objects_006.phpt]
method overloading with different method signature [Zend/tests/objects_007.phpt]
method overloading with different method signature [Zend/tests/objects_008.phpt]
method overloading with different method signature [Zend/tests/objects_009.phpt]

Let's decide the expected behavior, wait...
 [2009-02-03 19:51 UTC] cellog@php.net
the error occurs regardless of implementing an interface, and is, I believe, correct.  If $y were optional, there is no problem, and no error
 [2009-02-03 19:53 UTC] stas@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Overriding foo($x) with foo($x, $y) - with both parameters required - leads to calls to foo with one argument be wrong for child - thus violating LSP and warranting E_STRICT. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC