Get fileName property of PharFileInfo Object

290 views Asked by At

I have a PharData object and I want to get an array of filenames inside.

foreach($PharData as $object){
    print_r($object);
}

returns

PharFileInfo Object
(
[pathName:SplFileInfo:private] => phar://C:/.../arch.tar/pmnt.csv
[fileName:SplFileInfo:private] => pmnt.csv
)
...

How do I get fileName property? Tried $object->fileName but it says no such property. "Echo $object" gives pathName but I don't want to parse it for filename if there's easier way

2

There are 2 answers

1
Leonid Goriachkin On

Try to use

$object->getFilename();
0
Bruce On

Use this code

$info = new SplFileInfo('phar://C:/.../arch.tar/pmnt.csv');//your path to the file.
var_dump($info->getFilename());

Reference splfileinfo