We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
From manual page: https://php.net/function.exif-read-data
I got a JPG picture that has indeed a wrong color profile. So the function exif_read_data throws an E_WARNING.
exif_read_data
E_WARNING
But it's impossible to retrieve the error message using try / catch block like this:
try { $data = exif_read_data( __DIR__.'/mypicture.jpg', 'ANY_TAG' ); } catch (Throwable $e) { echo 'Error retrieved: ' . $e->getMessage() . PHP_EOL; }
The only way to retrieve the error message was like this:
$data = @exif_read_data(__DIR__.'/mypicture.jpg', 'ANY_TAG'); $error = error_get_last(); if ( false === $data && is_array($error) && in_array($error['type'], [E_WARNING, E_NOTICE]) && $error['file'] === __FILE__ && mb_stripos($error['message'], 'exif_read_data') !== false ) { echo 'error found in picture metadata: ' . $error['message'] . PHP_EOL; } else { echo 'metadata verified successfully' . PHP_EOL; }
In the attachment you'll find the faulty test picture.
I've tested it on cli with:
php -v PHP 8.1.27 (cli) (built: Dec 21 2023 20:17:59) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.27, Copyright (c) Zend Technologies with Zend OPcache v8.1.27, Copyright (c), by Zend Technologies
Since there's no new changelog, I assume this issue is still present in latest PHP version also.
The text was updated successfully, but these errors were encountered:
You have submitted this ticket as documentation issue, but this looks like an actual bug report. (Although I don't think there is a bug.)
Sorry, something went wrong.
What you might be looking for is a way to turn errors into exceptions:
// Set a custom error handler set_error_handler(function ($severity, $message, $file, $line) { throw new ErrorException($message, 0, $severity, $file, $line); }); try { // Call the exif_read_data function $data = exif_read_data( __DIR__.'/mypicture.jpg', 'ANY_TAG' ); print_r($data); } catch (Throwable $e) { echo 'Error retrieved: ' . $e->getMessage() . PHP_EOL; } finally { // Restore the original error handler restore_error_handler(); }
@msamesch hat ganz recht. Aber da ich gerade merke, dass wir hier in doc-de sind, können wir uns natürlich auch auf Deutsch unterhalten. :)
No branches or pull requests
From manual page: https://php.net/function.exif-read-data
I got a JPG picture that has indeed a wrong color profile. So the function
exif_read_data
throws anE_WARNING
.But it's impossible to retrieve the error message using try / catch block like this:
The only way to retrieve the error message was like this:
In the attachment you'll find the faulty test picture.
I've tested it on cli with:
Since there's no new changelog, I assume this issue is still present in latest PHP version also.
The text was updated successfully, but these errors were encountered: