tags:

views:

50

answers:

3

I have this class:

abstract class Hotel
{
    protected $util;

    function  __construct()
    {
        $this->util = new Utility();
    }

    function add(Validate $data, Model_Hotel $hotel){}

    function delete(){}

    function upload_image(array $imagedetails, $hotel_id){}
}

and a class that extends it

class Premium extends Hotel
{
    function add(Model_Hotel $hotel)
    {
        $hotel->values;
        $hotel->save();
    }

    function upload_image(array $imagedetails, $hotel_id)
    {
        $this->util->save_image($imagedetails, $hotel_id);
    }
}

but then I get an error:

"declaration of Premium::add must be compatible with Hotel::add"

as you can see, I left out a parameter for the add() method, which was intentional

what OOP facility would allow me to inherit a function whose parameters I can change? (Obviously an abstract class won't do here)

A: 

You could make your $data parameter optional

class Hotel {
    function add( Model_Hotel $hotel, Validate $data = null );
}
meouw
A: 

I am using php 5.2.12 and I (strangely) don't get any errors either way :(

AntonioCS
so that means, I can provide 1 or 2 parameters, provided that if I provide a second parameter, it must be of the same type as the declared function from the abstract class?
Ygam
I think that you are overriding the method, since it's not marked as final
AntonioCS
+1  A: 

It's an E_STRICT error. In PHP you can't overload methods (that's the OOP paradigm you're looking for), so your signature must be identical to the abstract version of the method, or else it's an error.

tmont