Skip to content

Commit

Permalink
error_log() is impure
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jan 22, 2024
1 parent a3d0910 commit 7c75d21
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/functionMetadata_original.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
'count' => ['hasSideEffects' => false],
'connection_aborted' => ['hasSideEffects' => true],
'connection_status' => ['hasSideEffects' => true],
'error_log' => ['hasSideEffects' => true],
'fclose' => ['hasSideEffects' => true],
'fflush' => ['hasSideEffects' => true],
'fgetc' => ['hasSideEffects' => true],
Expand Down
1 change: 1 addition & 0 deletions resources/functionMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@
'dngettext' => ['hasSideEffects' => false],
'doubleval' => ['hasSideEffects' => false],
'error_get_last' => ['hasSideEffects' => false],
'error_log' => ['hasSideEffects' => true],
'escapeshellarg' => ['hasSideEffects' => false],
'escapeshellcmd' => ['hasSideEffects' => false],
'exp' => ['hasSideEffects' => false],
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/trigger-error-php7.php');
}

yield from $this->gatherAssertTypes(__DIR__ . '/data/impure-error-log.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/falsy-isset.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/falsey-coalesce.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/falsey-ternary-certainty.php');
Expand Down
14 changes: 14 additions & 0 deletions tests/PHPStan/Analyser/data/impure-error-log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace ImpureErrorLog;

use function PHPStan\Testing\assertType;

function doFoo() {
$message = 'foo';
$logfile = 'bar/baz.txt';
if (!error_log($message, 3, $logfile)) {
assertType('bool', error_log($message, 3, $logfile));
}
}

0 comments on commit 7c75d21

Please sign in to comment.