|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-02-22 21:24 UTC] salathe@php.net
Description:
------------
The lower bound of the offset parameter for the FilterIterator is zero (no offset). When an offset less than zero is given, an OutOfBoundsException is thrown, incorrectly stating, "Parameter offset must be > 0".
Reproduce code:
---------------
<?php
$ait = new ArrayIterator(array('a', 'b', 'c'));
try {
$lit = new LimitIterator($ait, 0);
echo "OK\n";
} catch (OutOfRangeException $e) {
echo $e->getMessage() . "\n";
}
try {
$lit = new LimitIterator($ait, -1);
echo "OK\n";
} catch (OutOfRangeException $e) {
echo $e->getMessage() . "\n";
}
Expected result:
----------------
OK
Parameter offset must be >= 0
Actual result:
--------------
OK
Parameter offset must be > 0
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 23:00:01 2025 UTC |
The tiny, tiny patch (against trunk) would be: Index: spl_iterators.c =================================================================== --- spl_iterators.c (revision 295379) +++ spl_iterators.c (working copy) @@ -1321,7 +1321,7 @@ return NULL; } if (intern->u.limit.offset < 0) { - zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be > 0", 0 TSRMLS_CC); + zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be >= 0", 0 TSRMLS_CC); zend_restore_error_handling(&error_handling TSRMLS_CC); return NULL; }