Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice: A non well formed numeric value encountered in drush/drush/includes/drush.inc on line 894 #3039

Closed
zero2one opened this issue Oct 9, 2017 · 5 comments

Comments

@zero2one
Copy link
Contributor

zero2one commented Oct 9, 2017

Problem

The drush_memory_limit() code retrieves the memory limit and transforms it from human form into byte form.

The calculation uses the value as retrieves trough the ini_get('memory_limit') function. This value contains the human form (containing the byte size in K, M, G). The calculation triggers a notice in PHP 7.x

function drush_memory_limit() {
  $value = trim(ini_get('memory_limit'));
  //  Example value : 512M.
  $last = strtolower($value[strlen($value)-1]);
  switch ($last) {
    case 'g':
      $value *= DRUSH_KILOBYTE;
    case 'm':
      // This will cause the notice as is tries to do math with 
      // a numeric value and a string. 
      $value *= DRUSH_KILOBYTE;
    case 'k':
      $value *= DRUSH_KILOBYTE;
  }

  return $value;
}

Solution

Remove the order size from the value and use that value to calculate the memory limit.

function drush_memory_limit() {
  $value = trim(ini_get('memory_limit'));
  $last = strtolower($value[strlen($value)-1]);
  $size = (int) substr($value, 0, -1);
  switch ($last) {
    case 'g':
      $size *= DRUSH_KILOBYTE;
    case 'm':
      $size *= DRUSH_KILOBYTE;
    case 'k':
      $size *= DRUSH_KILOBYTE;
  }

  return $size;
}
@killes
Copy link

killes commented May 8, 2018

Could this be backported to Drush 8?

@weitzman
Copy link
Member

Backported.

@killes
Copy link

killes commented Jun 6, 2018

Thanks :)

@MacGuinness
Copy link

Perhaps I'm missing something subtle, but shouldn't the relevant switch options for 'g' & 'm' above be:

case 'g':
$size *= DRUSH_KILOBYTE * DRUSH_KILOBYTE * DRUSH_KILOBYTE;
case 'm':
$size *= DRUSH_KILOBYTE * DRUSH_KILOBYTE;

@angry-dan
Copy link

@MacGuinness you're right - it is subtle - there's no break statement so it (intentionally) falls through to the next case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants