php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47383 override declaration with non type hinted params should allow type hinting
Submitted: 2009-02-13 20:45 UTC Modified: 2010-08-13 00:01 UTC
From: info at netmosfera dot it Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.0beta1 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: info at netmosfera dot it
New email:
PHP Version: OS:

 

 [2009-02-13 20:45 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-13 21:15 UTC] 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?
 [2010-08-13 00:01 UTC] stas@php.net
-Status: Open +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2010-08-13 00:01 UTC] stas@php.net
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
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 21:01:31 2025 UTC