reactphp / socket

Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP.
https://reactphp.org/socket/
MIT License
1.2k stars 156 forks source link

Socket address of closed socket should be null (support PHP 8) #246

Closed clue closed 4 years ago

clue commented 4 years ago

The previous code works just fine on PHP 7 and older. PHP 8 adds stricter type checks for closed socket resources, so the underlying function now throws a TypeError. This can be avoided by first checking if the socket resource is still valid (not closed). This works across all PHP versions and also helps with avoiding some uneeded error suppression operators.

This means this component now supports PHP 8 just fine :tada:

~/workspace/reactphp-socket$ docker run -it --rm -v `pwd`:/data --workdir /data php:8.0.0beta1-cli php -d memory_limit=-1 vendor/bin/phpunit                                          
PHPUnit 9.3.7 by Sebastian Bergmann and contributors.                                                                                                                                          

....................................S..........................  63 / 304 ( 20%)                                                                                                               
..........SSS.................................................. 126 / 304 ( 41%)                                                                                                               
............................................................... 189 / 304 ( 62%)                                                                                                               
..........................................................S.... 252 / 304 ( 82%)                                                                                                               
....................................................            304 / 304 (100%)                                                                                                               

Time: 00:08.058, Memory: 628.00 MB                                                                                                                                                             

OK, but incomplete, skipped, or risky tests!                                                                                                                                                   
Tests: 304, Assertions: 641, Skipped: 5.

This PR does not currently include PHP 8 in the Travis test matrix. PHP is scheduled to be released in November, I'll file a follow-up PR once it's available for installation on Travis.

Builds on top of #243 and #244