The samples provided in the documentation don't work
alexmocanu opened this issue · comments
The documentation needs to be updated. None of the provided examples seem to be working.
The code sample provided here https://amphp.org/getting-started/tcp-chat/basic-echo-server throws this error:
PHP Fatal error: Uncaught TypeError: Argument 1 passed to {closure}() must be an instance of Amp\Socket\ServerSocket, instance of Amp\Socket\ResourceSocket given, called in [REDACTED]vendor/amphp/amp/lib/functions.php on line 60 and defined in [REDACTED]/test.php:13
Same thing here: https://amphp.org/getting-started/tcp-chat/broadcasting - i only tried running the first code sample
PHP Fatal error: Uncaught TypeError: Argument 1 passed to class@anonymous::handleClient() must be an instance of Amp\Socket\ServerSocket, instance of Amp\Socket\ResourceSocket given, called in [REDACTED]/index.php on line 20 and defined in [REDACTED]/index.php:25
I think the documentation needs to be updated. None of the provided examples seem to be working.
The code sample provided here https://amphp.org/getting-started/tcp-chat/basic-echo-server throws this error:
PHP Fatal error: Uncaught TypeError: Argument 1 passed to {closure}() must be an instance of Amp\Socket\ServerSocket, instance of Amp\Socket\ResourceSocket given, called in [REDACTED]vendor/amphp/amp/lib/functions.php on line 60 and defined in [REDACTED]/test.php:13
Same thing here: https://amphp.org/getting-started/tcp-chat/broadcasting - i only tried running the first code sample
PHP Fatal error: Uncaught TypeError: Argument 1 passed to class@anonymous::handleClient() must be an instance of Amp\Socket\ServerSocket, instance of Amp\Socket\ResourceSocket given, called in [REDACTED]/index.php on line 20 and defined in [REDACTED]/index.php:25
Steps to reproduce:
- Create a new test directory:
mkdir test; cd test
- Within that test directory download amphp/socket:
composer require amphp/socket
- Create a test.php file, copy and paste one of the samples then execute the file with this command:
php test.php
This will start the script and wait for connections - From another terminal try to connect with "nc":
nc localhost 1337
As soon as nc attempts to connect the script will throw the errors mentioned above.
Tested on:
- Ubuntu 18.04 with PHP 7.2.19 (installed from the distro's official repositories)
- MacOS 10.14.6 with PHP 7.3.4 (installed with homebrew)
These are for the 0.10.x version, indeed. We've updated the socket docs, but didn't update the docs in the getting started guide yet, which is a separate repository. Thanks for the hint!
I added this in the correct place here:
amphp/amphp.github.io#20 (comment)
The actual correct place is https://github.com/amphp/getting-started :P
I've updated all examples but the last one, so they should work properly with the latest version now. Thanks!