Skip to content

Commit 1285815

Browse files
committed
Fix function array dereferencing syntax for PHP 5.3
1 parent 80fdb7a commit 1285815

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Collection.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ public function bulkWrite(array $bulk, array $options = array())
178178
throw new \InvalidArgumentException(sprintf("Missing argument#2 for '%s' (operation#%d)", $opname, $n));
179179
}
180180
$options = array_merge($this->getWriteOptions(), isset($args[2]) ? $args[2] : array(), array("limit" => 1));
181-
if (key($args[1])[0] != '$') {
181+
$firstKey = key($args[1]);
182+
if (!isset($firstKey[0]) || $firstKey[0] != '$') {
182183
throw new \InvalidArgumentException("First key in \$update must be a \$operator");
183184
}
184185

@@ -190,7 +191,8 @@ public function bulkWrite(array $bulk, array $options = array())
190191
throw new \InvalidArgumentException(sprintf("Missing argument#2 for '%s' (operation#%d)", $opname, $n));
191192
}
192193
$options = array_merge($this->getWriteOptions(), isset($args[2]) ? $args[2] : array(), array("limit" => 1));
193-
if (key($args[1])[0] == '$') {
194+
$firstKey = key($args[1]);
195+
if (isset($firstKey[0]) && $firstKey[0] == '$') {
194196
throw new \InvalidArgumentException("First key in \$update must NOT be a \$operator");
195197
}
196198

@@ -456,7 +458,8 @@ public function findOneAndDelete(array $filter, array $options = array())
456458
*/
457459
public function findOneAndReplace(array $filter, array $replacement, array $options = array())
458460
{
459-
if (key($replacement)[0] == '$') {
461+
$firstKey = key($replacement);
462+
if (isset($firstKey[0]) && $firstKey[0] == '$') {
460463
throw new \InvalidArgumentException("First key in \$replacement must NOT be a \$operator");
461464
}
462465

@@ -493,7 +496,8 @@ public function findOneAndReplace(array $filter, array $replacement, array $opti
493496
*/
494497
public function findOneAndUpdate(array $filter, array $update, array $options = array())
495498
{
496-
if (key($update)[0] != '$') {
499+
$firstKey = key($update);
500+
if (!isset($firstKey[0]) || $firstKey[0] != '$') {
497501
throw new \InvalidArgumentException("First key in \$update must be a \$operator");
498502
}
499503

@@ -964,7 +968,8 @@ public function listIndexes()
964968
*/
965969
public function replaceOne(array $filter, array $update, array $options = array())
966970
{
967-
if (key($update)[0] == '$') {
971+
$firstKey = key($update);
972+
if (isset($firstKey[0]) && $firstKey[0] == '$') {
968973
throw new \InvalidArgumentException("First key in \$update must NOT be a \$operator");
969974
}
970975
$wr = $this->_update($filter, $update, $options);
@@ -1005,7 +1010,8 @@ public function updateMany(array $filter, $update, array $options = array())
10051010
*/
10061011
public function updateOne(array $filter, array $update, array $options = array())
10071012
{
1008-
if (key($update)[0] != '$') {
1013+
$firstKey = key($update);
1014+
if (!isset($firstKey[0]) || $firstKey[0] != '$') {
10091015
throw new \InvalidArgumentException("First key in \$update must be a \$operator");
10101016
}
10111017
$wr = $this->_update($filter, $update, $options);

0 commit comments

Comments
 (0)