This is a solution to the problem of argument type based overloading in PHP. As far as I know this should work in PHP4 and PHP5.
class Viewer {
function display($v) {
$class = get_class($v);
$function = "display_$class";
if(method_exists($this, $function) ){
$this->$function($v);
} else {
$this->display_default($v);
}
}
}
This class can then be extended and used like this:
class PDOViewer extends Viewer {
function display_PDO($item) {
echo "This is a PDO item";
}
}
$viewer = new PDOViewer;
$viewer->display(new PDO);