Skip to content

File Put Contents file with empty content #7467

@ghost

Description

Preconditions:

  • Magento ver. 2.1.1 installed

Steps to reproduce

  1. Call $driverFile->filePutContents('file.txt', '')
    where driverFile is an instance of \Magento\Framework\Filesystem\Driver\File

Expected result

  1. file.txt contains is created

Actual result

  1. getting error The specified "file.text" file could not be written

Solution

In code:

        $result = @file_put_contents($this->getScheme() . $path, $content, $mode);
        if (!$result) {
            throw new FileSystemException(
                new \Magento\Framework\Phrase(
                    'The specified "%1" file could not be written %2',
                    [$path, $this->getWarningMessage()]
                )
            );
        }

Check should be
if ($result !== false) { ... } instead of if (!$result) { ... }

As per PHP Manual:

This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.2.xThe issue has been fixed in 2.2 release lineIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions