Skip to content

Commit 5fb9807

Browse files
committed
[CP-17568] - fixing current return types
Assisted-by: Claude Code
1 parent 0651bfb commit 5fb9807

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

phalcon/Mvc/Model/Resultset/Simple.zep

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ class Simple extends Resultset
121121
let activeRow = this->activeRow;
122122

123123
if activeRow !== null {
124-
return activeRow;
124+
/**
125+
* `false` marks a row that could not hydrate. It stops the row
126+
* check below running a second time; it is not a value to give
127+
* back.
128+
*/
129+
return activeRow === false ? null : activeRow;
125130
}
126131

127132
/**

tests/database/Mvc/Model/Resultset/CurrentTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,46 @@ public function testMvcModelResultsetCurrent(string $type, ?string $expected): v
7070

7171
$this->assertInstanceOf($expected, $current);
7272
}
73+
74+
/**
75+
* The same holds once a populated resultset has been iterated to the end.
76+
*
77+
* @author Phalcon Team <team@phalcon.io>
78+
* @since 2026-09-04
79+
*/
80+
#[Group('mysql')]
81+
#[Group('pgsql')]
82+
#[Group('sqlite')]
83+
public function testMvcModelResultsetCurrentTwiceAfterExhaustion(): void
84+
{
85+
$resultset = $this->getResultset('simple');
86+
87+
foreach ($resultset as $record) {
88+
$this->assertInstanceOf(Invoices::class, $record);
89+
}
90+
91+
$this->assertNull($resultset->current());
92+
$this->assertNull($resultset->current());
93+
}
94+
95+
/**
96+
* A second `current()` at a position with no row gives back `null` again.
97+
* The `false` the first call stores is a sentinel that stops the row check
98+
* running twice; it is not a value to give back.
99+
*
100+
* @author Phalcon Team <team@phalcon.io>
101+
* @since 2026-09-04
102+
*/
103+
#[Group('mysql')]
104+
#[Group('pgsql')]
105+
#[Group('sqlite')]
106+
public function testMvcModelResultsetCurrentTwiceOnEmpty(): void
107+
{
108+
$resultset = $this->getResultset('empty');
109+
110+
$resultset->rewind();
111+
112+
$this->assertNull($resultset->current());
113+
$this->assertNull($resultset->current());
114+
}
73115
}

0 commit comments

Comments
 (0)