You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The getVersion method is documented to return only a single period:
/**
* The version of the browser.
* @return string Version of the browser (will only contain alpha-numeric characters and a period)
*/
public function getVersion()
{
return $this->_version;
}
However, it may contain multiple. E.g. '15.1.4'.
This was not really an obvious issue, until PHP 8, which changes how automatic casting works...
php -r 'var_dump("15.1.4" == 15.1);'
bool(false)
It returns false as it now does a string comparison rather than an automatic cast, if it doesn't fully match the pattern of a float (I think!!). I was relying on this, as I'm sure other users were.
This change to the setVersion method fixes it by making it only have one period section:
/**
* Set the version of the browser
* @param string $version The version of the Browser
*/
public function setVersion($version)
{
$this->_version = preg_replace('#^([^\.]*\.[^\.]*)\..*#', '$1', preg_replace('/[^0-9,.,a-z,A-Z-]/', '', $version));
}
This provides us a return value that continues to work...
$ php -r 'var_dump("15.1" == 15.1);'
bool(true)
The text was updated successfully, but these errors were encountered:
@chrisgraham definitely an issue - I hear you. For an acceptable stopgap in PHP8 you could cast to a double; I'd really like to not change the setter/getter scenario of the version if we can (just due to usage)
That's fine, thanks for the reply.
If you don't want to go my way for now, I suggest just securing the way you're doing it. Fix "will only contain alpha-numeric characters and a period" to "will only contain alpha-numeric characters and periods, e.g. 15.1.4", and actually I'd advise people to use PHP's version_compare function.
The
getVersion
method is documented to return only a single period:However, it may contain multiple. E.g. '15.1.4'.
This was not really an obvious issue, until PHP 8, which changes how automatic casting works...
php -r 'var_dump("15.1.4" == 15.1);'
bool(false)
It returns false as it now does a string comparison rather than an automatic cast, if it doesn't fully match the pattern of a float (I think!!). I was relying on this, as I'm sure other users were.
This change to the
setVersion
method fixes it by making it only have one period section:This provides us a return value that continues to work...
The text was updated successfully, but these errors were encountered: