Skip to content

[BUG]: Model::groupResult() return type is too restrictive #17114

@FredericSchwarz

Description

@FredericSchwarz

Description

Phalcon\Mvc\Model::groupResult() is declared with the return type Phalcon\Mvc\Model\ResultsetInterface, but it can return scalar values when used by aggregate methods such as count(), sum(), average(), maximum(), and minimum().

This causes issues when extending Phalcon\Mvc\Model. Any overriding implementation must declare a compatible return type (ResultsetInterface), but the parent method may actually return scalar values. As a result, custom model classes cannot safely override groupResult() without risking runtime TypeError exceptions.

TypeError: Return value must be of type Phalcon\Mvc\Model\ResultsetInterface, int returned

Current signature

protected static function groupResult(
    string $functionName,
    string $alias,
    $parameters = null
): ResultsetInterface

Problem

The implementation returns the resultset when a group clause is present, but otherwise returns the aggregate value from the first row:

return $firstRow->{$alias};

This value is typically an int, float, or string, not a ResultsetInterface.

Metadata

Metadata

Assignees

Labels

5.0The issues we want to solve in the 5.0 releasebugA bug reportstatus: mediumMedium

Type

No fields configured for Bug.

Projects

Status
Implemented

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions