- Phpdbg:
. Fixed bug #76813 (Access violation near NULL on source operand). (cmb)
+- SPL:
+ . Fixed #62004 (SplFileObject: fgets after seek returns wrong line). (cmb)
+
- Standard:
. Fixed bug #80366 (Return Value of zend_fstat() not Checked). (sagpant, cmb)
- SPL:
. SplFileObject::fgetss() has been removed.
+ . SplFileObject::seek() now always seeks to the beginning of the line.
+ Previously, positions >=1 sought to the beginning of the next line.
. SplHeap::compare($a, $b) now specifies a method signature. Inheriting
classes implementing this method will now have to use a compatible
method signature.
PHP_METHOD(SplFileObject, seek)
{
spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(ZEND_THIS);
- zend_long line_pos;
+ zend_long line_pos, i;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &line_pos) == FAILURE) {
RETURN_THROWS();
spl_filesystem_file_rewind(ZEND_THIS, intern);
- while(intern->u.file.current_line_num < line_pos) {
+ for (i = 0; i < line_pos; i++) {
if (spl_filesystem_file_read_line(ZEND_THIS, intern, 1) == FAILURE) {
- break;
+ return;
}
}
+ if (line_pos > 0) {
+ intern->u.file.current_line_num++;
+ spl_filesystem_file_free_line(intern);
+ }
} /* }}} */
/* {{{ PHP_MINIT_FUNCTION(spl_directory) */
//line 5
$s = new SplFileObject(__FILE__);
-$s->seek(12);
+$s->seek(13);
$s->next();
var_dump($s->key());
var_dump($s->valid());
?>
--EXPECT--
-int(13)
+int(14)
bool(false)
--EXPECT--
//line 3
//line 4
-//line 3
//line 4
+//line 5
--- /dev/null
+first,line
+second,line
+third,line
+fourth,line
+fifth,line
--- /dev/null
+--TEST--
+Bug #46569 (SplFileObject: fgetcsv after seek returns wrong line)
+--FILE--
+<?php
+$file = new SplFileObject(__DIR__ . '/bug46569.csv');
+$file->seek(1);
+print_r($file->fgetcsv());
+?>
+--EXPECT--
+Array
+(
+ [0] => second
+ [1] => line
+)
--- /dev/null
+--TEST--
+Bug #62004 (SplFileObject: fgets after seek returns wrong line)
+--FILE--
+<?php
+$f = new SplFileObject(__DIR__ . '/bug62004.txt');
+$f->setFlags(SplFileObject::SKIP_EMPTY);
+$f->seek(0);
+echo $f->fgets();
+$f->seek(1);
+echo $f->fgets();
+$f->seek(2);
+echo $f->fgets();
+?>
+--EXPECT--
+Line 1
+Line 2
+Line 3
--- /dev/null
+Line 1
+Line 2
+Line 3
+Line 4
echo $s->getCurrentLine();
?>
--EXPECT--
+//line 2
//line 3
-//line 4