Hopefully you can see what I am trying to. I don't want to use
return $class->display(); in content because I am assuming that I dont know the name of the method that I will be calling in there.
It could be useful to just do that. You could create an interface construct (e.g., call it Displayable) that has a display() member function, then have the content() member function take an argument of that interface type. Then to put this together, have the weather class implement that interface construct.
EDIT:
For example:
<?php
interface Displayable
{
function display();
}
class Dialog
{
function create($title)
{
return "<div class='dialog'><div class='dialogTitle'>$title</div>";
}
function content(Displayable $item)
{
return $item->display();
}
function close()
{
return "</div>";
}
}
class Weather implements Displayable
{
private $town;
function __construct($town)
{
$this->town = $town;
}
function display()
{
return "I live in " . $this->town;
}
}
$weather = new Dialog();
echo $weather->create("Weather");
echo $weather->content(new Weather("Campbeltown"));
echo $weather->close();
?>
By the way, note that the constructor is __construct, not _construct. It is probably better to name the dialog $dialog or $weather_dialog instead of $weather when you have a class named Weather.