#33347 [Fbk->Opn]: Function overloading type hinting inconsistencies
| From: | levi at alliancesoftware dot com dot au | Date: | Thu, 16 Jun 2005 01:32:37 +0000 |
| Subject: | #33347 [Fbk->Opn]: Function overloading type hinting inconsistencies | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-80407@lists.php.net to get a copy of this message | ||
ID: 33347
User updated by: levi at alliancesoftware dot com dot au
Reported By: levi at alliancesoftware dot com dot au
-Status: Feedback
+Status: Open
Bug Type: Zend Engine 2 problem
Operating System: Fedora Core 2
-PHP Version: 5.0.4
+PHP Version: 5.x
New Comment:
Occurs with both 5.0 CVS (repository checkout) and 5.1 CVS snapshot
(from snapshots page) as of 2005-06-16
Previous Comments:
------------------------------------------------------------------------
[2005-06-15 15:24:50] sniper@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5-win32-latest.zip
------------------------------------------------------------------------
[2005-06-15 06:45:42] levi at alliancesoftware dot com dot au
Description:
------------
When overloading a function and changing the type hinting, php :
- Allows you to change the type hint for a regular overloaded function
- Flags an error when you change the type hint for an implemented
abstract function (even for descendants)
- Flags an error when you change the type hint for an implemented
interface function (even for descendants)
This happens if the type hinting is at all different: tighter
restrictions (subclass of the original type) or looser restrictions (no
type hint at all).
Reproduce code:
---------------
<?
class X { }
class Y extends X { }
abstract class Ancestor {
public function func(X $x) { }
abstract public function abstractFunc(X $x);
}
interface Inter {
public function interFunc(X $x);
}
class Descendant extends Ancestor implements Inter {
public function func(X $x) { }
public function abstractFunc(X $x) { }
public function interFunc(X $x) { }
}
class Descendant2 extends Descendant {
public function func(Y $x) { } // allowed
public function abstractFunc(Y $x) { } // error
public function interFunc($x) { } // error
}
?>
Expected result:
----------------
I would hope the type hints were totally ignored and the parser
should only ensure the same number of paramaters.
At the very minimum, Descendant2 should be allowed to change the type
hints even if Descendant was forced to use the original hints. It seems
inconsistent to treate ordinary method overloading differently to
method overloading from methods that were in an interface or originally
abstract.
Actual result:
--------------
PHP Fatal error: Declaration of Descendant2::abstractFunc() must be
compatible with that of Ancestor::abstractFunc() in
/home/levi/public_html/testD.php5 on line 23
PHP Fatal error: Declaration of Descendant2::interFunc() must be
compatible with that of Inter::interFunc() in
/home/levi/public_html/testD.php5 on line 23
Note that Descendant::abstractFunc() was more restrictive (parameter "Y
$y") and Descendant::interFunc() was less restrictive (parameter "$x")
-- the error is flagged if the type hint is at all different.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33347&edit=1