Skip to content
Prev Previous commit
Next Next commit
Mark mysqli_connect as having side effects in function metadata
mysqli_connect establishes a network connection to a database server,
which is inherently a side effect. Marking it as hasSideEffects => true
causes TypeSpecifier to return empty SpecifiedTypes for the call, which
prevents stale conditional expressions from being created and fixes the
false positive logicalOr.leftAlwaysTrue on repeated calls.

Fixes phpstan/phpstan#14473

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
  • Loading branch information
phpstan-bot and claude committed Apr 15, 2026
commit 36db1ffe434fc74dcf6454813cbf79d3b2eb93cf
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
Loading