Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Filename cannot be empty

Description

fopen()’s first argument is of type string, though the empty string is not allowed, as it does not lead to any file.

This check prevents using an empty string, or its equivalent as null or false, to access a file.

This error also applies to file_get_contents and file_put_contents(). It doesn’t apply to unlink and rmdir.

Example

<?php

fopen('', 'r');

?>

Alternatives

  • Check the name of the file with empty() before using it with fopen().
  • Check the name of the file against ‘’ (empty string) before using it with fopen().

In more recent PHP versions, this error message is now :ref:path-cannot-be-empty.