Skip to content

SplFileObject::fwrite raises alwaysFalse violation on php >= 7.4 #13208

Closed
phpstan/phpstan-src
#4087
@SmasherHell

Description

@SmasherHell

Bug report

The following code raise an alwaysFalse violation:

                $file = new \SplFileObject('/tmp/file', "wd+");
		if ($file->fwrite('a') === false) { // Should not raise alwaysFalse for php >= 7.4 as per the php documentation https://www.php.net/manual/en/splfileobject.fwrite.php
			throw new \Exception("write failed !");
		}

The php documentation specify that since php 7.4, false is returned when fwrite fails. Since \SplFileInfo::isWritable does not promise the file will be written.

Code snippet that reproduces the problem

https://phpstan.org/r/17742407-4eb8-48a1-ab9e-f32b219ecf97

Expected output

No violation on php >= 7.4

Did PHPStan help you today? Did it make you happy in any way?

I love phpstan, all contributors are heroes in my eye.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions