-php options can return empty array instead of nothing

Started by luboz, February 18, 2025, 12:39:49 PM

Previous topic - Next topic

luboz

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?

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

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

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).