Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
use function sprintf;
use function str_ends_with;
use function substr;
use const PHP_SAPI;

/**
* @api
Expand Down Expand Up @@ -138,7 +139,7 @@ public function create(
$configurator->addParameters(array_merge([
'rootDir' => $this->rootDirectory,
'currentWorkingDirectory' => $this->currentWorkingDirectory,
'cliArgumentsVariablesRegistered' => ini_get('register_argc_argv') === '1',
'cliArgumentsVariablesRegistered' => PHP_SAPI === 'cli' || ini_get('register_argc_argv') === '1',
'tmpDir' => $tempDirectory,
'additionalConfigFiles' => $additionalConfigFiles,
'allConfigFiles' => $allConfigFiles,
Expand Down
23 changes: 23 additions & 0 deletions tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,29 @@ public function testBug6688(): void
]);
}

public function testBug14585(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/bug-14585.php'], []);
}

public function testBug14585NotRegistered(): void
{
$this->cliArgumentsVariablesRegistered = false;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/bug-14585.php'], [
[
'Variable $argv might not be defined.',
7,
],
]);
}

#[RequiresPhp('>= 8.0.0')]
public function testBug10729(): void
{
Expand Down
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-14585.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types = 1);

if (PHP_SAPI !== 'cli') {
exit("This script can not run outside of shell\n");
}

foreach ($argv as $argument) {
if (preg_match('/^--server-name=(.+)/', $argument, $matches)) {
$foo = $matches[1];
break;
}
}
Loading