ZF-7223: In Zend_Db_Select::limit(), an empty first parameter won't be converted to max integer in 32-bits architecture.


In Zend_Db_Select class, the _renderLimitoffset function tries to get the max integer that PHP can support when no count parameter is given but in 32-bits architecture, intval(9223372036854775807) returns 0 instead of reducing to the max integer.

$select->from('Table')->limit(0, 5);

Will give you

SELECT Table.* FROM Table

Instead of

SELECT Table.* FROM Table LIMIT 2147483647 OFFSET 5

Using intval('9223372036854775807') - parameter as a string - will return the max value in both 32-bits and 64-bits architecture but more simply PHP_INT_MAX can be used.


Fixed with r19154

This goes against the documentation. Please see… for expected behaviour.

According to the documentation, the function


Should produce:

SELECT Table.* FROM Table LIMIT 0, 5

Taking the same syntax the the original reporter has for the SQL statement produced, it should be:


The current fix gives produces the opposite actions compared to what is provided in the documentation.

Fisrt, the aim of the fix is to get the max integer PHP can support.

Second, the documentation is wrong according to the code :

->limit(10, 20); // ->limit($row_count, $offset)

won't get

LIMIT 10, 20 // [offset,] row_count or LIMIT 20 OFFSET 10


LIMIT 20, 10 or LIMIT 10 OFFSET 20

Third, in the current logic of the using of limit clause, it is impossible to have a empty row count value.

@Michael Beaumont: the first parameter is the count and the second is the offset If the count equals 0, we assume that you want all values.

See…, for real modifications to the code or… for the associated test:

$select->from('table1')->limit(0, 5);


'SELECT "table1".* FROM "table1" LIMIT ' . PHP_INT_MAX . ' OFFSET 5'

@Michael Beaumont: It appears that it's a documentation issue (see ZF-6237)