Req #47383 [Opn->Bgs]: override declaration with non type hinted params should allow type hinting

From: Date: Thu, 12 Aug 2010 22:01:36 +0000
Subject: Req #47383 [Opn->Bgs]: override declaration with non type hinted params should allow type hinting
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-153385@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=47383&edit=1

 ID:                 47383
 Updated by:         stas@php.net
 Reported by:        info at netmosfera dot it
 Summary:            override declaration with non type hinted params
                     should allow type hinting
-Status:             Open
+Status:             Bogus
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 Operating System:   *
 PHP Version:        5.3.0beta1
 Block user comment: N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

Method arguments are supposed to be contravariant, see:
http://en.wikipedia.org/wiki/Liskov_substitution_principle
http://en.wikipedia.org/wiki/Covariance_and_contravariance_%28computer_science%29#Need_for_covariant_argument_types.3F


Previous Comments:
------------------------------------------------------------------------
[2009-02-13 21:15:49] info at netmosfera dot it

better explanation:

class a
{
    function a(File $x){echo get_class($x);}
}

class b extends a
{
    function a(ImageFile $x){echo get_class($x);}
}

this obviously works!

now, if mixed means "accepts everything"

class a
{
    function a(Mixed $x){echo get_class($x);}
}

i should be able to override it:

class b extends a
{
    function a(File $x){echo get_class($x);}
}

no?

------------------------------------------------------------------------
[2009-02-13 20:45:43] info at netmosfera dot it

Description:
------------
hello

i think that non-type-hinted arguments (mixed values):

class a
{
     function test([mixed] $argument){}
}

should allow type hinting in child classes

class b extends a
{
     function test(ImageFile $argument){}
}

Reproduce code:
---------------
"mixed" is a general type... means "everything"
but if i want to build an ArrayObject object with one-only type

i cannot do this

[internal]
class ArrayObject implements ArrayAccess
{
      function offsetSet($o, [mixed] $value)
      {}
}

class ImageList extends ArrayObject
{
      function offsetSet($o, Image $imageObject) // fatal error!
      {}
}

Actual result:
--------------
Fatal error: Declaration of ImageList::offsetSet() must be compatible
with that of ArrayAccess::offsetSet() in xx on line 8

thank you


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=47383&edit=1


Thread (3 messages)

« previous php.bugs (#153385) next »