1--TEST-- 2Phar object: iterating via SplFileObject 3--SKIPIF-- 4<?php if (!extension_loaded("phar")) die("skip"); ?> 5--INI-- 6phar.require_hash=0 7--FILE-- 8<?php 9 10$pharconfig = 1; 11 12require_once 'files/phar_oo_test.inc'; 13 14$phar = new Phar($fname); 15$phar->setInfoClass('SplFileObject'); 16 17$f = $phar['a.csv']; 18echo "===1===\n"; 19foreach($f as $k => $v) 20{ 21 echo "$k=>$v\n"; 22} 23 24$f->setFlags(SplFileObject::DROP_NEW_LINE); 25 26echo "===2===\n"; 27foreach($f as $k => $v) 28{ 29 echo "$k=>$v\n"; 30} 31 32class MyCSVFile extends SplFileObject 33{ 34 function current() 35 { 36 return parent::fgetcsv(',', '"'); 37 } 38} 39 40$phar->setInfoClass('MyCSVFile'); 41$v = $phar['a.csv']; 42 43echo "===3===\n"; 44while(!$v->eof()) 45{ 46 echo $v->key() . "=>" . join('|',$v->fgetcsv()) . "\n"; 47} 48 49echo "===4===\n"; 50$v->rewind(); 51while(!$v->eof()) 52{ 53 $l = $v->fgetcsv(); 54 echo $v->key() . "=>" . join('|',$l) . "\n"; 55} 56 57echo "===5===\n"; 58foreach($v as $k => $d) 59{ 60 echo "$k=>" . join('|',$d) . "\n"; 61} 62 63class MyCSVFile2 extends SplFileObject 64{ 65 function getCurrentLine() 66 { 67 echo __METHOD__ . "\n"; 68 return parent::fgetcsv(',', '"'); 69 } 70} 71 72$phar->setInfoClass('MyCSVFile2'); 73$v = $phar['a.csv']; 74 75echo "===6===\n"; 76foreach($v as $k => $d) 77{ 78 echo "$k=>" . join('|',$d) . "\n"; 79} 80 81?> 82--CLEAN-- 83<?php 84unlink(__DIR__ . '/files/phar_oo_008.phar.php'); 85__halt_compiler(); 86?> 87--EXPECT-- 88===1=== 890=>1,2,3 90 911=>2,a,b 92 932=>3,"c","'e'" 94===2=== 950=>1,2,3 961=>2,a,b 972=>3,"c","'e'" 98===3=== 990=>1|2|3 1000=>2|a|b 1011=>3|c|'e' 102===4=== 1030=>1|2|3 1041=>2|a|b 1052=>3|c|'e' 106===5=== 1070=>1|2|3 1081=>2|a|b 1092=>3|c|'e' 110===6=== 111MyCSVFile2::getCurrentLine 1121=>1|2|3 113MyCSVFile2::getCurrentLine 1143=>2|a|b 115MyCSVFile2::getCurrentLine 1165=>3|c|'e' 117