Skip to content

Commit

Permalink
Protect from serializing a closure object.
Browse files Browse the repository at this point in the history
Instead of preventing the serialization of all callable values (such as names of functions or those created by create_function), it's better to only prevent the serialization of the Closure object.
  • Loading branch information
KendallHopkins committed Sep 25, 2011
1 parent f5b74aa commit 304b43e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions PHPUnit/Util/GlobalState.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function backupGlobals(array $blacklist)
if ($key != 'GLOBALS' &&
!in_array($key, $superGlobalArrays) &&
!in_array($key, $blacklist) &&
!is_callable($GLOBALS[$key])) {
!(is_object($GLOBALS[$key]) && $GLOBALS[$key] instanceof Closure)) {
self::$globals['GLOBALS'][$key] = serialize($GLOBALS[$key]);
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ 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])) {
if (is_object($GLOBALS[$superGlobalArray][$key]) && $GLOBALS[$superGlobalArray][$key] instanceof Closure) {
continue;
}

Expand All @@ -250,7 +250,7 @@ public static function getGlobalsAsString()
$blacklist[] = '_PEAR_Config_instance';

foreach (array_keys($GLOBALS) as $key) {
if (!in_array($key, $blacklist) && !is_callable($GLOBALS[$key])) {
if (!in_array($key, $blacklist) && !(is_object($GLOBALS[$key]) && $GLOBALS[$key] instanceof Closure)) {
$result .= sprintf(
'$GLOBALS[\'%s\'] = %s;' . "\n",
$key,
Expand Down Expand Up @@ -306,7 +306,7 @@ public static function backupStaticAttributes(array $blacklist)
$attribute->setAccessible(TRUE);
$value = $attribute->getValue();

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

0 comments on commit 304b43e

Please sign in to comment.