Skip to content

Commit

Permalink
Fixes yiisoft#4220: Fixed PHP 7.2 incompatibility caused by the use o…
Browse files Browse the repository at this point in the history
…f `create_function` in CProfileLogRoute
  • Loading branch information
freezy-sk authored and samdark committed Feb 12, 2019
1 parent 7c81bc2 commit e23e15c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Version 1.1.21 under development
--------------------------------

- Bug #4220: Fixed PHP 7.2 incompatibility caused by the use of `create_function` in CHttpRequest (martinpetrasch)
- Bug #4220: Fixed PHP 7.2 incompatibility caused by the use of `create_function` in CHttpRequest and CProfileLogRoute (martinpetrasch, freezy-sk)
- Bug #4229: Remove deprecation errors from framework/web/js/source/jquery.yiiactiveform.js when using jQuery 3.1.1 (kenguest)
- Bug #4234: CVE-2018-14773. Drop support for HTTP_X_REWRITE_URL (kenguest)
- Chg #4236: Freeze session before changing ini settings to be compatible with PHP 7.2 (vxk7m)
Expand Down
17 changes: 14 additions & 3 deletions framework/logging/CProfileLogRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,23 @@ protected function displaySummary($logs)
}

$entries=array_values($results);
$func=create_function('$a,$b','return $a[4]<$b[4]?1:0;');
usort($entries,$func);
usort($entries, array($this, 'resultEntryCompare'));

$this->render('profile-summary',$entries);
}

/**
* Result entry compare function used by usort.
* Included to circumvent the use of closures (not supported by PHP 5.2) and create_function (deprecated since PHP 7.2.0)
* @param array $a
* @param array $b
* @return int 0 (a>=b), 1 (a<b)
*/
private function resultEntryCompare($a, $b)
{
return ($a[4] < $b[4]) ? 1 : 0;
}

/**
* Aggregates the report result.
* @param array $result log result for this code block
Expand All @@ -202,4 +213,4 @@ protected function aggregateResult($result,$delta)
$total+=$delta;
return array($token,$calls,$min,$max,$total);
}
}
}

0 comments on commit e23e15c

Please sign in to comment.