Permalink
Browse files

The $val = '1k' * 1024 cause a "Notice: A non well formed numeric val…

…ue encountered" with PHP 7.1 (#761)
  • Loading branch information...
matyasb authored and mrook committed Aug 24, 2017
1 parent a0b146e commit 64b3cf2e77c6dbbb3e42945a3c5ef7eb313f46f1
Showing with 32 additions and 11 deletions.
  1. +13 −11 classes/phing/Phing.php
  2. +19 −0 test/classes/phing/PhingTest.php
View
@@ -1580,21 +1580,23 @@ private static function setIncludePaths()
* @param string $val
* @return int
*/
private static function convertShorthand($val)
public static function convertShorthand($val)
{
$val = trim($val);
$last = strtolower($val[strlen($val) - 1]);
$val = (int) $val;
switch ($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
if (!is_numeric($last)) {
$val = (int) substr($val, 0, strlen($val) - 1);
switch ($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
}
return $val;
@@ -67,6 +67,25 @@ public function testImportDotPath()
self::assertTrue(class_exists(self::DOTED_CLASS_SHORTNAME));
}
/**
* Test the convertShorthand function
*/
public function testConvertShorthand()
{
self::assertEquals(0, Phing::convertShorthand('0'));
self::assertEquals(-1, Phing::convertShorthand('-1'));
self::assertEquals(100, Phing::convertShorthand('100'));
self::assertEquals(1024, Phing::convertShorthand('1k'));
self::assertEquals(1024, Phing::convertShorthand('1K'));
self::assertEquals(2048, Phing::convertShorthand('2K'));
self::assertEquals(1048576, Phing::convertShorthand('1M'));
self::assertEquals(1048576, Phing::convertShorthand('1m'));
self::assertEquals(1073741824, Phing::convertShorthand('1G'));
self::assertEquals(1073741824, Phing::convertShorthand('1g'));
self::assertEquals(200, Phing::convertShorthand('200j'));
}
/**
* Get fixtures classpath
*

0 comments on commit 64b3cf2

Please sign in to comment.