tags:

views:

120

answers:

1

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.
    }
}
+1  A: 

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
does this mean I can't use type hinting?
Andrew
You can. The type hinting just has to be identical on every implementation of the function.
Frank Farmer
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
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
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