#33347 [NEW]: Function overloading type hinting inconsistencies

From: Date: Wed, 15 Jun 2005 04:45:44 +0000
Subject: #33347 [NEW]: Function overloading type hinting inconsistencies
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-80350@lists.php.net to get a copy of this message
From: levi at alliancesoftware dot com dot au Operating system: Fedora Core 2 PHP version: 5.0.4 PHP Bug Type: Zend Engine 2 problem Bug description: Function overloading type hinting inconsistencies 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 bug report at http://bugs.php.net/?id=33347&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33347&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33347&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33347&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=33347&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=33347&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=33347&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=33347&r=needscript Try newer version: http://bugs.php.net/fix.php?id=33347&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=33347&r=support Expected behavior: http://bugs.php.net/fix.php?id=33347&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=33347&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=33347&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=33347&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33347&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=33347&r=dst IIS Stability: http://bugs.php.net/fix.php?id=33347&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=33347&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=33347&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=33347&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=33347&r=mysqlcfg

« previous php.bugs (#80350) next »