Skip to content

Commit

Permalink
Do not try to serialize() anonymous functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Aug 24, 2011
1 parent c6ab0fc commit 01aa347
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ PHPUnit 3.5

This is the list of changes for the PHPUnit 3.5 release series.

PHPUnit 3.5.16
--------------

* `PHPUnit_Util_GlobalState` no longer tries to `serialize()` anonymous functions.

PHPUnit 3.5.15
--------------

Expand Down
15 changes: 12 additions & 3 deletions PHPUnit/Util/GlobalState.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public static function backupGlobals(array $blacklist)
foreach (array_keys($GLOBALS) as $key) {
if ($key != 'GLOBALS' &&
!in_array($key, $superGlobalArrays) &&
!in_array($key, $blacklist)) {
!in_array($key, $blacklist) &&
!is_callable($GLOBALS[$key])) {
self::$globals['GLOBALS'][$key] = serialize($GLOBALS[$key]);
}
}
Expand Down Expand Up @@ -226,6 +227,10 @@ public static function getGlobalsAsString()
if (isset($GLOBALS[$superGlobalArray]) &&
is_array($GLOBALS[$superGlobalArray])) {
foreach (array_keys($GLOBALS[$superGlobalArray]) as $key) {
if (is_callable($GLOBALS[$superGlobalArray][$key])) {
continue;
}

$result .= sprintf(
'$GLOBALS[\'%s\'][\'%s\'] = %s;' . "\n",
$superGlobalArray,
Expand All @@ -241,7 +246,7 @@ public static function getGlobalsAsString()
$blacklist[] = '_PEAR_Config_instance';

foreach (array_keys($GLOBALS) as $key) {
if (!in_array($key, $blacklist)) {
if (!in_array($key, $blacklist) && !is_callable($GLOBALS[$key])) {
$result .= sprintf(
'$GLOBALS[\'%s\'] = %s;' . "\n",
$key,
Expand Down Expand Up @@ -294,7 +299,11 @@ public static function backupStaticAttributes(array $blacklist)
if (!isset($blacklist[$declaredClasses[$i]]) ||
!in_array($name, $blacklist[$declaredClasses[$i]])) {
$attribute->setAccessible(TRUE);
$backup[$name] = serialize($attribute->getValue());
$value = $attribute->getValue();

if (!is_callable($value)) {
$backup[$name] = serialize($value);
}
}
}
}
Expand Down

0 comments on commit 01aa347

Please sign in to comment.