diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php
index 8d58dc5d1202..207022e8b3f4 100644
--- a/src/Illuminate/Collections/Collection.php
+++ b/src/Illuminate/Collections/Collection.php
@@ -1129,13 +1129,13 @@ public function before($value, $strict = false)
             return null;
         }
 
-        $position = $this->keys()->search($key);
+        $position = ($keys = $this->keys())->search($key);
 
         if ($position === 0) {
             return null;
         }
 
-        return $this->get($this->keys()->get($position - 1));
+        return $this->get($keys->get($position - 1));
     }
 
     /**
@@ -1153,13 +1153,13 @@ public function after($value, $strict = false)
             return null;
         }
 
-        $position = $this->keys()->search($key);
+        $position = ($keys = $this->keys())->search($key);
 
-        if ($position === $this->keys()->count() - 1) {
+        if ($position === $keys->count() - 1) {
             return null;
         }
 
-        return $this->get($this->keys()->get($position + 1));
+        return $this->get($keys->get($position + 1));
     }
 
     /**