Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#2210 from weierophinne…
Browse files Browse the repository at this point in the history
…y/hotfix/remove-suppression-operator

Get rid of error suppression
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
27 changes: 17 additions & 10 deletions src/Pattern/CallbackCache.php
Expand Up @@ -12,6 +12,7 @@

use Zend\Cache\Exception;
use Zend\Cache\StorageFactory;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -145,19 +146,22 @@ protected function generateCallbackKey($callback, array $args)
$object = $callback[0];
}
if (isset($object)) {
ErrorHandler::start();
try {
$serializedObject = @serialize($object);
$serializedObject = serialize($object);
} catch (\Exception $e) {
ErrorHandler::stop();
throw new Exception\RuntimeException(
"Can't serialize callback: see previous exception", 0, $e
);
}
$error = ErrorHandler::stop();

if (!$serializedObject) {
$lastErr = error_get_last();
throw new Exception\RuntimeException(
"Can't serialize callback: " . $lastErr['message']
);
throw new Exception\RuntimeException(sprintf(
'Cannot serialize callback%s',
($error ? ': ' . $error->getMessage() : '')
), 0, $error);
}
$callbackKey.= $serializedObject;
}
Expand All @@ -178,19 +182,22 @@ protected function generateArgumentsKey(array $args)
return '';
}

ErrorHandler::start();
try {
$serializedArgs = @serialize(array_values($args));
$serializedArgs = serialize(array_values($args));
} catch (\Exception $e) {
ErrorHandler::stop();
throw new Exception\RuntimeException(
"Can't serialize arguments: see previous exception"
, 0, $e);
}
$error = ErrorHandler::stop();

if (!$serializedArgs) {
$lastErr = error_get_last();
throw new Exception\RuntimeException(
"Can't serialize arguments: " . $lastErr['message']
);
throw new Exception\RuntimeException(sprintf(
'Cannot serialize arguments%s',
($error ? ': ' . $error->getMessage() : '')
), 0, $error);
}

return md5($serializedArgs);
Expand Down
9 changes: 6 additions & 3 deletions src/Storage/Adapter/AdapterOptions.php
Expand Up @@ -96,10 +96,13 @@ public function setKeyPattern($keyPattern)
if ($keyPattern !== '') {
ErrorHandler::start(E_WARNING);
$result = preg_match($keyPattern, '');
ErrorHandler::stop();
$error = ErrorHandler::stop();
if ($result === false) {
$err = error_get_last();
throw new Exception\InvalidArgumentException("Invalid pattern '{$keyPattern}': {$err['message']}");
throw new Exception\InvalidArgumentException(sprintf(
'Invalid pattern "%s"%s',
$keyPattern,
($error ? ': ' . $error->getMessage() : '')
), 0, $error);
}
}

Expand Down

0 comments on commit 5975f0e

Please sign in to comment.