Skip to content
1 change: 1 addition & 0 deletions bin/functionMetadata_original.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
'link' => ['hasSideEffects' => true],
'mkdir' => ['hasSideEffects' => true],
'move_uploaded_file' => ['hasSideEffects' => true],
'mysqli_connect' => ['hasSideEffects' => true],
'ob_clean' => ['hasSideEffects' => true],
'ob_end_clean' => ['hasSideEffects' => true],
'ob_end_flush' => ['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 @@ -1392,6 +1392,7 @@
'msgfmt_parse_message' => ['hasSideEffects' => false],
'mt_getrandmax' => ['hasSideEffects' => false],
'mt_rand' => ['hasSideEffects' => true],
'mysqli_connect' => ['hasSideEffects' => true],
'net_get_interfaces' => ['hasSideEffects' => false],
'ngettext' => ['hasSideEffects' => false],
'nl2br' => ['hasSideEffects' => false],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,11 @@ public function testBug10305(): void
]);
}

public function testBug14473(): void
{
$this->treatPhpDocTypesAsCertain = true;

$this->analyse([__DIR__ . '/data/bug-14473.php'], []);
}

}
27 changes: 27 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-14473.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types = 1);

namespace Bug14473;

$link = mysqli_connect('host', 'user', 'pass', 'database') or die('Could not connect: ' . mysqli_connect_error());

// (assume long-running code that can cause the connection to time out)

$link = mysqli_connect('host', 'user', 'pass', 'database') or die('Could not reconnect: ' . mysqli_connect_error());

// okay, so let's make certain that the connection is closed
mysqli_close($link);

$link = mysqli_connect('host', 'user', 'pass', 'database') or die('Could not reconnect: ' . mysqli_connect_error());

// close it and destroy the variable
mysqli_close($link);
unset($link);

$link = mysqli_connect('host', 'user', 'pass', 'database') or die('Could not reconnect: ' . mysqli_connect_error());

// close, destroy ...
mysqli_close($link);
unset($link);

// ... and assign to a different variable
$newLink = mysqli_connect('host', 'user', 'pass', 'database') or die('Could not reconnect: ' . mysqli_connect_error());
Loading