#42330 [NEW]: Type hinting based upon interfaces not working
| From: | udo dot rader at bestsolution dot at | Date: | Fri, 17 Aug 2007 17:31:48 +0000 |
| Subject: | #42330 [NEW]: Type hinting based upon interfaces not working | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-116257@lists.php.net to get a copy of this message | ||
From: udo dot rader at bestsolution dot at
Operating system: Linux
PHP version: 5.2.3
PHP Bug Type: Scripting Engine problem
Bug description: Type hinting based upon interfaces not working
Description:
------------
When using type hinting with interfaces it fails to recognoize classes
implementing the interface as "compatible".
Reproduce code:
---------------
abstract class Foo {
abstract public function saySomething( IBar $what );
abstract public function saySomethingElse( IBar $what );
}
class BarDAO extends Foo {
function saySomething( IBar $what ) {
echo $what->getMessage();
}
function saySomethingElse( BarTransfer $what ) {
echo $what->getMessage();
}
}
interface IBar {
function getMessage();
}
class BarTransfer implements IBar {
function getMessage() {
return "Hello from BarTransfer";
}
}
$barDAO = new BarDAO();
$barTransfer = new BarTransfer();
$barDAO->saySomething( $barTransfer );
$barDAO->saySomethingElse( $barTransfer );
Expected result:
----------------
The expected result should be that no compiler error occurs and that the
script runs.
Actual result:
--------------
The PHP interpreter gives this error:
Fatal error: Declaration of BarDAO::saySomethingElse() must be compatible
with that of Foo::saySomethingElse()
But, IMHO, BarTransfer can hardly be more "compatible" with IBar.
--
Edit bug report at http://bugs.php.net/?id=42330&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=42330&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=42330&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=42330&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=42330&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=42330&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=42330&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=42330&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=42330&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=42330&r=support
Expected behavior: http://bugs.php.net/fix.php?id=42330&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=42330&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=42330&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=42330&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42330&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=42330&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=42330&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=42330&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=42330&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=42330&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=42330&r=mysqlcfg