Reputation: 8111
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)
Upvotes: 1
Views: 210
Reputation: 2630
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.
Upvotes: 2
Reputation: 42140
You could make your $data parameter optional
class Hotel {
function add( Model_Hotel $hotel, Validate $data = null );
}
Upvotes: 0