From: webmaster at domiwitt dot de
Operating system: Win XP Professional
PHP version: 5.1.2
PHP Bug Type: Class/Object related
Bug description: Inherited methods cannot specialize/change type hints
Description:
------------
On an inherited methods that uses parameter type hints it is not possible
to specialize a type hint. By "specialize" I mean that the type hint on
the inheriting class's method is able to type check an inherited class of
the previous type hint.
I have found several cases, where this behaviour would be extemely useful.
The Specification Pattern poses a good example.
Certainly you can work around it by not using type hints and do some
"instanceof" or "get_class()" checking inside, throwing an exception in
unwanted cases. It would however be nice if the language itself could
support such a behaviour.
Reproduce code:
---------------
<?php
interface ISpecification {
public static function isSpecifiedBy($object);
}
class FooSpecification implements ISpecification {
public static function isSpecifiedBy($object) {
echo get_class($object);
}
}
class BarSpecification implements ISpecification {
public static function isSpecifiedBy($object) {
echo get_class($object);
}
}
class Foo { }
class Bar extends Foo { }
FooSpecification::isSpecifiedBy(new Foo());
BarSpecification::isSpecifiedBy(new Bar());
?>
Expected result:
----------------
For this not to throw a compile time error
Actual result:
--------------
Fatal error: Access level to FooSpecification::isSpecifiedBy() must be
public (as in class ISpecification) in [...] on line 9
--
Edit bug report at http://bugs.php.net/?id=36601&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=36601&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=36601&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=36601&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36601&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=36601&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36601&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36601&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36601&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36601&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36601&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=36601&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=36601&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36601&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36601&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36601&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36601&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36601&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36601&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36601&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36601&r=mysqlcfg