ID:               36601
 Updated by:       [EMAIL PROTECTED]
 Reported By:      webmaster at domiwitt dot de
-Status:           Open
+Status:           Wont fix
 Bug Type:         Class/Object related
 Operating System: Win XP Professional
 PHP Version:      5.1.2
 New Comment:

We discussed this in the PDM, see:
http://www.php.net/~derick/meeting-notes.html#implement-inheritance-rules-for-type-hints


Previous Comments:
------------------------------------------------------------------------

[2006-03-03 09:57:10] webmaster at domiwitt dot de

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 this bug report at http://bugs.php.net/?id=36601&edit=1

Reply via email to