Skip to content

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Nov 25, 2024

php-version dependent socket_create handling to ease writing cross php version code

refs phpstan/phpstan#4212

see https://php.watch/versions/8.0/sockets-sockets-addressinfo

@staabm staabm force-pushed the socket_create branch 2 times, most recently from 48a48c8 to 16ba677 Compare November 26, 2024 08:11
@staabm staabm marked this pull request as ready for review November 26, 2024 08:23
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm
Copy link
Contributor Author

staabm commented Nov 26, 2024

broken build is unrelated

@staabm staabm marked this pull request as draft November 26, 2024 18:40
@staabm
Copy link
Contributor Author

staabm commented Nov 26, 2024

just found https://php.watch/versions/8.0/sockets-sockets-addressinfo which describes all functions which have been changed from resource to Socket-objects.
I have double checked the php.net manual for all of them and it turned out they have the same parameter signature so we can re-use the extension for all of them.

@staabm staabm marked this pull request as ready for review November 26, 2024 19:01
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes
Copy link
Member

I'm hesitant to merge this. If PHPStan were to properly merge reflection data across multiple supported PHP versions then this PR wouldn't be needed at all. It's really weird to implement this for a single function when the rest of PHPStan doesn't really support this.

@thg2k
Copy link
Contributor

thg2k commented Jan 16, 2025

I'm hesitant to merge this. If PHPStan were to properly merge reflection data across multiple supported PHP versions then this PR wouldn't be needed at all. It's really weird to implement this for a single function when the rest of PHPStan doesn't really support this.

I agree. I think PHPStan should have its own meta-type that automatically resolves to the correct type (i.e. resource/object) according to the current php version.

At the moment i'm happily using this hack: phpstan/phpstan#4212 (comment)

The problem is that it works only within the same project, i.e. as the phpstan.neon file is local to the project it does not "export" easily, so for methods facing externally I have to type it as "mixed".

These are the type aliases i'm currently using:

	typeAliases: (php 7.x)
		resource_gd: 'resource'
		resource_gdfont: 'int'
		resource_socket: 'resource'

	typeAliases: (php 8.x)
		resource_gd: '\GdImage'
		resource_gdfont: '\GdFont'
		resource_socket: '\Socket'

Also note that some types have been introduced in different versions, so for example GdImage and Socket are 8.0 while GdFont is 8.1

@staabm staabm closed this Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants