Skip to content

How do you handle PHP 8 resources-which-got-converted-to-objects? #4212

Answered by ondrejmirtes
Seldaek asked this question in Support
Discussion options

You must be logged in to vote

Hi,
yeah, Socket|resource|false is most precise if you need to support both PHP 7 and 8.

Currently the best way to run PHPStan on such codebases is to run it twice, for both PHP 7 and PHP 8. You'll have to run it with different config files as some code is marked as invalid for PHP 7 (for example the Socket class doesn't exist there), and some code is not necessary on PHP 8, like checking for === false for functions that no longer return false.

Unfortunately that's currently the best way to do it, but not ideal. PHPStan currently supports only a single PHP version to consider for a codebase, not a range, as I explained here at length: #4060 (comment)

At least you can reuse the common part…

Replies: 4 comments 12 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Seldaek
Comment options

Answer selected by Seldaek
Comment options

You must be logged in to vote
2 replies
@ondrejmirtes
Comment options

@dktapps
Comment options

Comment options

You must be logged in to vote
9 replies
@AJenbo
Comment options

@ondrejmirtes
Comment options

@AJenbo
Comment options

@staabm
Comment options

@ondrejmirtes
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
6 participants