file_get_contents() Needs A Real Path¶
file_get_contents() cannot work on an empty string. Until PHP 8.0, it would report it as a warning, and return false, keeping the execution. In PHP 8.0, it is now a Fatal error.
PHP code¶
<?php
var_dump(file_get_contents());
?>
Before¶
PHP Warning: file_get_contents(): Filename cannot be empty in /codes/file_get_contents.php on line 3
Warning: file_get_contents(): Filename cannot be empty in /codes/file_get_contents.php on line 3
bool(false)
After¶
PHP Fatal error: Uncaught ValueError: Path cannot be empty in /codes/file_get_contents.php:3
Stack trace:
#0 /codes/file_get_contents.php(3): file_get_contents('')
#1 {main}
thrown in /codes/file_get_contents.php on line 3
Fatal error: Uncaught ValueError: Path cannot be empty in /codes/file_get_contents.php:3
Stack trace:
#0 /codes/file_get_contents.php(3): file_get_contents('')
#1 {main}
thrown in /codes/file_get_contents.php on line 3
PHP version change¶
This behavior changed in 8.0