Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 21 additions & 43 deletions ext/phar/tests/phar_oo_008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,34 @@ foreach($f as $k => $v)
echo "$k=>$v\n";
}

class MyCSVFile extends SplFileObject
class MyFile extends SplFileObject
{
function current(): array|false
function current(): string
{
return parent::fgetcsv(',', '"', escape: '');
return parent::fgets();
}
}

$phar->setInfoClass('MyCSVFile');
/** @var MyCSVFile $v */
$phar->setInfoClass('MyFile');
/** @var MyFile $v */
$v = $phar['a.csv'];

echo "===3===\n";
while(!$v->eof())
{
echo $v->key() . "=>" . join('|', $v->fgetcsv(escape: '')) . "\n";
echo $v->key() . "=>" . $v->fgets() . "\n";
}

echo "===4===\n";
$v->rewind();
while(!$v->eof())
{
$l = $v->fgetcsv(escape: '');
echo $v->key() . "=>" . join('|', $l) . "\n";
$l = $v->fgets();
echo $v->key() . "=>" . $l . "\n";
}

echo "===5===\n";
foreach($v as $k => $d)
{
echo "$k=>" . join('|', $d) . "\n";
}

class MyCSVFile2 extends SplFileObject
{
function getCurrentLine(): string
{
echo __METHOD__ . "\n";
return implode('|', parent::fgetcsv(',', '"', escape: ''));
}
}

$phar->setInfoClass('MyCSVFile2');
/** @var MyCSVFile2 $v */
$v = $phar['a.csv'];

echo "===6===\n";
foreach($v as $k => $d)
{
echo "$k=>" . $d . "\n";
}
Expand All @@ -98,21 +79,18 @@ __halt_compiler();
1=>2,a,b
2=>3,"c","'e'"
===3===
0=>1|2|3
0=>2|a|b
1=>3|c|'e'
0=>1,2,3

1=>2,a,b

2=>3,"c","'e'"
===4===
0=>1|2|3
1=>2|a|b
2=>3|c|'e'
1=>1,2,3

2=>2,a,b

3=>3,"c","'e'"
===5===
0=>1|2|3
1=>2|a|b
2=>3|c|'e'
===6===
MyCSVFile2::getCurrentLine
1=>1|2|3
MyCSVFile2::getCurrentLine
3=>2|a|b
MyCSVFile2::getCurrentLine
5=>3|c|'e'
1=>1,2,3

3=>3,"c","'e'"
142 changes: 142 additions & 0 deletions ext/phar/tests/phar_oo_009_fgetcsv.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
--TEST--
Phar object: iterating via SplFileObject
--EXTENSIONS--
phar
--INI--
phar.require_hash=0
--FILE--
<?php

$pharconfig = 1;

require_once 'files/phar_oo_test.inc';

$phar = new Phar($fname);
$phar->setInfoClass('SplFileObject');

$f = $phar['a.csv'];
echo "===1===\n";
foreach($f as $k => $v)
{
echo "$k=>$v\n";
}

$f->setFlags(SplFileObject::DROP_NEW_LINE);

echo "===2===\n";
foreach($f as $k => $v)
{
echo "$k=>$v\n";
}

class MyCSVFile extends SplFileObject
{
function current(): array|false
{
return parent::fgetcsv(',', '"', escape: '');
}
}

$phar->setInfoClass('MyCSVFile');
/** @var MyCSVFile $v */
$v = $phar['a.csv'];

echo "===3===\n";
while(!$v->eof())
{
echo $v->key() . "=>" . join('|', $v->fgetcsv(escape: '')) . "\n";
}

echo "===4===\n";
$v->rewind();
while(!$v->eof())
{
$l = $v->fgetcsv(escape: '');
echo $v->key() . "=>" . join('|', $l) . "\n";
}

echo "===5===\n";
foreach($v as $k => $d)
{
echo "$k=>" . join('|', $d) . "\n";
}

class MyCSVFile2 extends SplFileObject
{
function getCurrentLine(): string
{
echo __METHOD__ . "\n";
return implode('|', parent::fgetcsv(',', '"', escape: ''));
}
}

$phar->setInfoClass('MyCSVFile2');
/** @var MyCSVFile2 $v */
$v = $phar['a.csv'];

echo "===6===\n";
foreach($v as $k => $d)
{
echo "$k=>" . $d . "\n";
}

?>
--CLEAN--
<?php
unlink(__DIR__ . '/files/phar_oo_009_fgetcsv.phar.php');
__halt_compiler();
?>
--EXPECTF--
===1===
0=>1,2,3

1=>2,a,b

2=>3,"c","'e'"
===2===
0=>1,2,3
1=>2,a,b
2=>3,"c","'e'"
===3===

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
0=>1|2|3

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
0=>2|a|b

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
1=>3|c|'e'
===4===

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
0=>1|2|3

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
1=>2|a|b

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
2=>3|c|'e'
===5===

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
0=>1|2|3

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
1=>2|a|b

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
2=>3|c|'e'
===6===
MyCSVFile2::getCurrentLine

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
1=>1|2|3
MyCSVFile2::getCurrentLine

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
3=>2|a|b
MyCSVFile2::getCurrentLine

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
5=>3|c|'e'
4 changes: 4 additions & 0 deletions ext/spl/spl_directory.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,19 @@ public function fgets(): string {}
public function fread(int $length): string|false {}

/** @tentative-return-type */
#[\Deprecated(since: '8.6')]
public function fgetcsv(string $separator = ",", string $enclosure = "\"", string $escape = "\\"): array|false {}

/** @tentative-return-type */
#[\Deprecated(since: '8.6')]
public function fputcsv(array $fields, string $separator = ",", string $enclosure = "\"", string $escape = "\\", string $eol = "\n"): int|false {}

/** @tentative-return-type */
#[\Deprecated(since: '8.6')]
public function setCsvControl(string $separator = ",", string $enclosure = "\"", string $escape = "\\"): void {}

/** @tentative-return-type */
#[\Deprecated(since: '8.6')]
public function getCsvControl(): array {}

/**
Expand Down
27 changes: 22 additions & 5 deletions ext/spl/spl_directory_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SplFileObject::fflush function - basic test
/*
* test a successful flush
*/
$obj = New SplFileObject(__DIR__.'/SplFileObject_testinput.csv');
$obj = New SplFileObject(__DIR__.'/SplFileObject_testinput.txt');
var_dump($obj->fflush());

/*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SplFileObject::fpassthru function - basic functionality test
--FILE--
<?php
$obj = New SplFileObject(__DIR__.'/SplFileObject_testinput.csv');
$obj = New SplFileObject(__DIR__.'/SplFileObject_testinput.txt');
$obj->fpassthru();
?>
--EXPECT--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SplFileObject::fscanf function - basic functionality test
--FILE--
<?php
$obj = New SplFileObject(__DIR__.'/SplFileObject_testinput.csv');
$obj = New SplFileObject(__DIR__.'/SplFileObject_testinput.txt');
var_dump($obj->fscanf('%s'));
?>
--EXPECT--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SplFileObject::fstat when fstat() has been disabled.
disable_functions="fstat"
--FILE--
<?php
$obj = New SplFileObject(__DIR__.'/SplFileObject_testinput.csv');
$obj = New SplFileObject(__DIR__.'/SplFileObject_testinput.txt');
var_dump($obj->fstat());
?>
--EXPECTF--
Expand Down
15 changes: 0 additions & 15 deletions ext/spl/tests/SplFileObject/bug46569.phpt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ var_dump($fo->fgetcsv());
<?php
unlink('SplFileObject__fgetcsv1.csv');
?>
--EXPECT--
--EXPECTF--
Deprecated: Method SplFileObject::setCsvControl() is deprecated since 8.6 in %s on line %d

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in %s on line %d
array(4) {
[0]=>
string(6) "field1"
Expand Down
Loading
Loading