I’m experiencing different behaviors in Laravel 7 and Laravel 9 regarding the Storage::get() method when the file does not exist. In Laravel 7, it throws a FileNotFoundException exception, while in Laravel 9, it returns null.
I’m curious about the reasons behind these changes. Why does Laravel 7 throw an exception while Laravel 9 returns null? Additionally, when I try to trace the implementation using XDebug, I find that the code interception is not occurring in the underlying filesystem.php.
Could someone provide insights into why this difference in behavior exists between Laravel 7 and Laravel 9, and why the interception is not happening as expected?
Code snippet (simplified):
<?php
// Laravel 7 behavior
try {
$content = Storage::get('nonexistent-file.txt');
// This block will not be executed if the file does not exist
echo $content;
} catch (IlluminateContractsFilesystemFileNotFoundException $e) {
// Handle the file not found exception
echo "File not found: " . $e->getMessage();
}
// Laravel 9 behavior
$content = Storage::get('nonexistent-file.txt');
if ($content === null) {
// Handle the case when the file does not exist
echo "File not found";
}