At the moment I have 2 a “Photo” class and a “Photo_Small” class which extends the photo class.
Here is the code for these (simplified for readability):-
[CODE]
class Photo{
protected $src;
protected $username;
protected $size;
protected $classname = “regular”;
public function __construct($src,$username){
$this->src = $src;
$this->username = $username;
}
public function render(){
return ‘<img title=”‘.$this->username.'” class=”‘.$this->classname.'” alt=”‘.$this->username.'” width=’.$this->size.’ height=’.$this->size.’ src=”images/’.$this->src.’.jpg”>’;
}
}
class Photo_Small{
public function __construct(){
$this->size = 50;
$this->classname = “small”;
}
}
The above code works fine as long as I do this:-
[CODE]
$photo = new Photo(1,”john123″);
echo $photo->render();
However I want to be able to create small photos easily (baring in mind the Photo_Small class will have a lot more things going on in it’s constructor than in my example here) like this:-
[CODE]
$photo = new Photo_Small(1,”john123″);
echo $photo->render();
But in this last example the constructor of the Photo_Small class is overwriting the parent constructor so none of the arguments passed in are being applied.
How can I get it to work so that I can just type “new Photo_Small(1,”john123″)” and all of the arguments will be passed, the Photo constructor will fire and then the child constructor will fire?