ExifTool Forum

ExifTool => Bug Reports / Feature Requests => Topic started by: luboz on February 18, 2025, 12:39:49 PM

Title: -php options can return empty array instead of nothing
Post by: luboz on February 18, 2025, 12:39:49 PM
I'm sorry to disturbing here, but I'm a bit surprised with output for -php option.
When there are files, ExifTool return data in PHP array syntax, but when there no valid file, output is empty.
Therefore my PHP line based on code from documentation
eval('$subory_exif=' . `exiftool -PHP -q -Title -ext docx -ext dotx -ext xlsx -ext xltx -ext pdf "$folder"`); isn't sometimes valid and there is an error "Parse error: syntax error, unexpected end of file in *** : eval()'d code on line 1".
If ExifTool will for this case return "Array();", it will be ok for PHP.

Or did I only overlook something and there is an option for this?
Title: Re: -php options can return empty array instead of nothing
Post by: Phil Harvey on February 19, 2025, 12:23:20 PM
Good point.  I'll think about this.

- Phil
Title: Re: -php options can return empty array instead of nothing
Post by: Phil Harvey on February 20, 2025, 09:27:19 AM
I've considered this.  I don't like the idea of outputting something when no files are processed.  This would be different from all other output formats, and I don't want to go there (should the XML output option also emit valid XML when nothing is processed?).

I think this is better handled in your PHP code by first storing the returned result

$result = `exiftool -PHP -q -Title -ext docx -ext dotx -ext xlsx -ext xltx -ext pdf "$folder"`;
Then testing this result before evaluating it.

- Phil