0

I have an abstract class. I'm extending that class. I'm getting this error:

Fatal error: Declaration of Default_Model_FoobarMapper::_setClassVarsFromRow() must be compatible with that of Default_Model_AbstractMapper::_setClassVarsFromRow() in /location/to/models/FoobarMapper.php on line 3

What does this usually mean?

Update: Found out that my type hinting was throwing an error. You can't do this:

abstract class MyAbstractClass
{
    abstract protected function _myFunction($array, $generic_class);
}

class Foobar extends MyAbstractClass
{
    protected function _myFunction($array, Specific_Class $specific_class)
    {
        //etc.
    }
}
Andrew
  • 227,796
  • 193
  • 515
  • 708

1 Answers1

4

The arguments you declare for _setClassVarsFromRow() must be identical to those in the abstract.

For example, if your abstract says

function _setClassVarsFromRow($arg1, $arg2 = null)

you can't implement

function _setClassVarsFromRow($arg1, $arg2, $arg3 = null)
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • 1
    does this mean I can't use type hinting? – Andrew Dec 11 '09 at 01:37
  • You can. The type hinting just has to be identical on every implementation of the function. – Frank Farmer Dec 11 '09 at 01:41
  • uh... I think you should be able to, as long as you hint the same types, shouldn't you? I haven't used type hinting in PHP yet so I don't know for sure. – Pekka Dec 11 '09 at 01:41
  • 6
    I think Andrew's meaning is this: If the abstract definition (written by somebody else) doesn't use type hinting, does this mean he can't add it to his implementation? And I'm afraid it means what he fears it means. (I just did a quick test.) – grossvogel Dec 11 '09 at 01:47
  • Andrew: To produce a small bit of type safety, you could always just pass the params through to another, type-hinted method, maybe '_setClassVarsFromRow_internal()' or something. – grossvogel Dec 11 '09 at 01:49
  • 1
    In some case, if an abstract says: `function ($arg1, $arg2)` you can't implement `function($arg1, $arg2 = null)` event if the arguments count is the same. – Aryo Mar 12 '12 at 05:36