I have a hierarchy of classes representing html elements. Some of them may not be compatible with some browser versions. The HTML5 canvas, for exemple, is not compatible with Internet Explorer before version 9.
I would like, for each type of element, to be able to know if they are or not supported by the calling browser.
abstract class AbstractView // Base class, doesn't represent anything.
{
// ...
// By default, an element will be considered compatible with any version of ny browser.
protected static $FirstCompatibleVersions = array(
'Firefox' => 0,
'Chrome' => 0,
'Internet Explorer' => 0);
protected static function SetFirstCompatibleVersion($browser, $version)
{
static::$FirstCompatibleVersions[$browser] = $version;
}
protected static function IsSupportedByBrowser()
{
$browser = // ... Assumed to be the calling browser name.
$version = // ... Assumed to be the calling browser version.
return static::$FirstCompatibleVersions[$browser] <= $version;
}
}
class CanvasView extends AbstractView // Displays a canvas. Not compatible with IE < 9.
{
// ...
}
CanvasView::SetFirstCompatibleVersion('Internet Explorer', 9);
class FormView extends AbstractView // Displays a form. Assumed compatible with anything.
{
// ...
}
// Nothing to do form FormView.
echo FormView::IsSupportedByBrowser(); // Should print 1 (true) (on firefox 12) but does not.
My problem is that, when i execute :
CanvasView::SetFirstCompatibleVersion('Internet Explorer', 9);
This will not only set CanvasView::$FirstCompatibleVersion['Internet Explorer'], but it will also set this value for all other classes, just like this array was common to all of the classes, making all my elements incompatible with IE < 9.
What can i do to prevent this ?
Thanks for taking the time to read.
-Virus