php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42439 Derivating a method in a class that implements an interface that declares it
Submitted: 2007-08-27 09:35 UTC Modified: 2007-08-30 11:33 UTC
From: romain dot tartiere at healthgrid dot org Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.3 OS: GNU/Linux
Private report: No CVE-ID: None
 [2007-08-27 09:35 UTC] romain dot tartiere at healthgrid dot org
Description:
------------
Considering a class that implements an interface and has methods that require many arguments. You may expect to make your life easier derivating this class and providing simpler methods.

Reproduce code:
---------------
<?php

interface i_foo {
        function fooize($str, $n);
}

class c_foo implements i_foo { /* painful ($class->fooize($str, $n)) */
        function fooize($str, $n) {
                echo "$str $n\n";
        }
}

class c_bar extends c_foo {
        function fooize($str) { /* simple ($class->fooize($str)) */
                $n = strlen($str);
                parent::fooize($str, $n);
        }
}

?>

Expected result:
----------------
This should not pose any kind of problem.

Actual result:
--------------
Fatal error: Declaration of c_bar::fooize() must be compatible with that of i_foo::fooize()

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-27 10:24 UTC] jani@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


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 23:01:28 2024 UTC