File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -143,10 +143,10 @@ public function __construct($query, $statement)
143
143
$ this ->_hydrate = $ this ->_query ->hydrate ();
144
144
$ this ->_entityClass = $ repository ->entityClass ();
145
145
$ this ->_useBuffering = $ query ->bufferResults ();
146
- $ this ->count ();
147
146
148
147
if ($ this ->_useBuffering ) {
149
- $ this ->_results = new SplFixedArray ($ this ->_count );
148
+ $ count = $ this ->count ();
149
+ $ this ->_results = new SplFixedArray ($ count );
150
150
}
151
151
}
152
152
@@ -217,22 +217,26 @@ public function rewind()
217
217
*/
218
218
public function valid ()
219
219
{
220
- if ($ this ->_index >= $ this ->_count ) {
220
+ $ valid = true ;
221
+ if ($ this ->_useBuffering ) {
222
+ $ valid = $ this ->_index < $ this ->_count ;
223
+ if ($ valid && $ this ->_results [$ this ->_index ] !== null ) {
224
+ $ this ->_current = $ this ->_results [$ this ->_index ];
225
+ return true ;
226
+ }
227
+ }
228
+
229
+ if (!$ valid ) {
221
230
if ($ this ->_statement !== null ) {
222
231
$ this ->_statement ->closeCursor ();
223
232
}
224
233
return false ;
225
234
}
226
235
227
- if ($ this ->_useBuffering && $ this ->_results [$ this ->_index ] !== null ) {
228
- $ this ->_current = $ this ->_results [$ this ->_index ];
229
- return true ;
230
- }
231
-
232
236
$ this ->_current = $ this ->_fetchResult ();
233
237
$ valid = $ this ->_current !== false ;
234
238
235
- if ($ this ->_useBuffering ) {
239
+ if ($ valid && $ this ->_useBuffering ) {
236
240
$ this ->_results [$ this ->_index ] = $ this ->_current ;
237
241
}
238
242
You can’t perform that action at this time.
0 commit comments