Closed mkamarin closed 4 years ago
Noticed that $val has a character (g, m, or k) appended at the end, which I should have noticed in the first place. Fixed the code as follows:
protected function returnBytes($val)
{
$val = trim($val);
$last = strtolower($val[strlen($val) - 1]);
$val = substr($val, 0, -1); // Remove the last character
switch ($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$val *= (int)1073741824;
break;
case 'm':
$val *= (int)1048576;
break;
case 'k':
$val *= (int)1024;
break;
}
return $val . $last; // <= return value as expected
}
Should I generate a pull request?
There is already a PR #1010. It even covers the case where no modifier is given (aka bytes). So, it is already in the master
branch but that was after the 1.4.0
release. So you might need to use the git version is order to get the bug fixed.
I will close this issue as it seems to be already fixed in my understanding. If you find this is a false assumption please comment, I can reopen then.
BTW: Your PHP version is too new. PartKeepr only supports PHP <= 7.1.
I am having the same error. Using PartKeepr 1.4.0 (downloaded couple of weeks ago) on Linux Mint 20 with XAMPP (XAMPP for Linux 7.4.8 [PHP 7.4.8] https://www.apachefriends.org/index.html).
The php_error_log includes the following line:
[01-Aug-2020 17:50:45 America/Los_Angeles] PHP Notice: A non well formed numeric value encountered in /xxxxxx/www/htdocs/partkeepr-1.4.0/app/PartKeeprRequirements.php on line 126
The problem is in:
Tried casting the line as follows:
but it does not solve the problem. Any suggestion will be welcome, as I don't know what to do next.
Originally posted by @mkamarin in https://github.com/partkeepr/PartKeepr/issues/980#issuecomment-667609939