@@ -178,7 +178,8 @@ public function bulkWrite(array $bulk, array $options = array())
178
178
throw new \InvalidArgumentException (sprintf ("Missing argument#2 for '%s' (operation#%d) " , $ opname , $ n ));
179
179
}
180
180
$ 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 ] != '$ ' ) {
182
183
throw new \InvalidArgumentException ("First key in \$update must be a \$operator " );
183
184
}
184
185
@@ -190,7 +191,8 @@ public function bulkWrite(array $bulk, array $options = array())
190
191
throw new \InvalidArgumentException (sprintf ("Missing argument#2 for '%s' (operation#%d) " , $ opname , $ n ));
191
192
}
192
193
$ 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 ] == '$ ' ) {
194
196
throw new \InvalidArgumentException ("First key in \$update must NOT be a \$operator " );
195
197
}
196
198
@@ -456,7 +458,8 @@ public function findOneAndDelete(array $filter, array $options = array())
456
458
*/
457
459
public function findOneAndReplace (array $ filter , array $ replacement , array $ options = array ())
458
460
{
459
- if (key ($ replacement )[0 ] == '$ ' ) {
461
+ $ firstKey = key ($ replacement );
462
+ if (isset ($ firstKey [0 ]) && $ firstKey [0 ] == '$ ' ) {
460
463
throw new \InvalidArgumentException ("First key in \$replacement must NOT be a \$operator " );
461
464
}
462
465
@@ -493,7 +496,8 @@ public function findOneAndReplace(array $filter, array $replacement, array $opti
493
496
*/
494
497
public function findOneAndUpdate (array $ filter , array $ update , array $ options = array ())
495
498
{
496
- if (key ($ update )[0 ] != '$ ' ) {
499
+ $ firstKey = key ($ update );
500
+ if (!isset ($ firstKey [0 ]) || $ firstKey [0 ] != '$ ' ) {
497
501
throw new \InvalidArgumentException ("First key in \$update must be a \$operator " );
498
502
}
499
503
@@ -964,7 +968,8 @@ public function listIndexes()
964
968
*/
965
969
public function replaceOne (array $ filter , array $ update , array $ options = array ())
966
970
{
967
- if (key ($ update )[0 ] == '$ ' ) {
971
+ $ firstKey = key ($ update );
972
+ if (isset ($ firstKey [0 ]) && $ firstKey [0 ] == '$ ' ) {
968
973
throw new \InvalidArgumentException ("First key in \$update must NOT be a \$operator " );
969
974
}
970
975
$ wr = $ this ->_update ($ filter , $ update , $ options );
@@ -1005,7 +1010,8 @@ public function updateMany(array $filter, $update, array $options = array())
1005
1010
*/
1006
1011
public function updateOne (array $ filter , array $ update , array $ options = array ())
1007
1012
{
1008
- if (key ($ update )[0 ] != '$ ' ) {
1013
+ $ firstKey = key ($ update );
1014
+ if (!isset ($ firstKey [0 ]) || $ firstKey [0 ] != '$ ' ) {
1009
1015
throw new \InvalidArgumentException ("First key in \$update must be a \$operator " );
1010
1016
}
1011
1017
$ wr = $ this ->_update ($ filter , $ update , $ options );
0 commit comments