Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fb88119

Browse filesBrowse files
committed
bug #27232 [Cache][Lock] Fix usages of error_get_last() (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [Cache][Lock] Fix usages of error_get_last() | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - When a userland error handler doesn't return `false`, `error_get_last()` is not updated, so we cannot see the real last error, but the previous one. See https://3v4l.org/Smmt7 Commits ------- 7904784 [Cache][Lock] Fix usages of error_get_last()
2 parents 98934e4 + 7904784 commit fb88119
Copy full SHA for fb88119

File tree

2 files changed

+8
-7
lines changed
Filter options

2 files changed

+8
-7
lines changed

‎src/Symfony/Component/Cache/Traits/RedisTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/RedisTrait.php
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,12 @@ public static function createConnection($dsn, array $options = array())
126126
throw new InvalidArgumentException(sprintf('Redis connection failed (%s): %s', $e->getMessage(), $dsn));
127127
}
128128

129-
if (@!$redis->isConnected()) {
130-
$e = ($e = error_get_last()) && preg_match('/^Redis::p?connect\(\): (.*)/', $e['message'], $e) ? sprintf(' (%s)', $e[1]) : '';
131-
throw new InvalidArgumentException(sprintf('Redis connection failed%s: %s', $e, $dsn));
129+
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
130+
$isConnected = $redis->isConnected();
131+
restore_error_handler();
132+
if (!$isConnected) {
133+
$error = preg_match('/^Redis::p?connect\(\): (.*)/', $error, $error) ? sprintf(' (%s)', $error[1]) : '';
134+
throw new InvalidArgumentException(sprintf('Redis connection failed%s: %s', $error, $dsn));
132135
}
133136

134137
if ((null !== $auth && !$redis->auth($auth))

‎src/Symfony/Component/Lock/Store/FlockStore.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Store/FlockStore.php
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ private function lock(Key $key, $blocking)
7878
);
7979

8080
// Silence error reporting
81-
set_error_handler(function () {
82-
});
81+
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
8382
if (!$handle = fopen($fileName, 'r')) {
8483
if ($handle = fopen($fileName, 'x')) {
8584
chmod($fileName, 0444);
@@ -91,8 +90,7 @@ private function lock(Key $key, $blocking)
9190
restore_error_handler();
9291

9392
if (!$handle) {
94-
$error = error_get_last();
95-
throw new LockStorageException($error['message'], 0, null);
93+
throw new LockStorageException($error, 0, null);
9694
}
9795

9896
// On Windows, even if PHP doc says the contrary, LOCK_NB works, see

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.