reactphp / http

Event-driven, streaming HTTP client and server implementation for ReactPHP.
https://reactphp.org/http/
MIT License
743 stars 142 forks source link

PHP 7.3 errors with arg #338

Closed overvoidjs closed 5 years ago

overvoidjs commented 5 years ago

Fatal error: Uncaught TypeError: Argument 1 passed to React\Http\Server::__construct() must be an instance of React\Socket\ServerInterface, instance of Closure given, called in /var/www/html/apiz/test.php on line 19 and defined in /var/www/html/vendor/react/http/src/Server.php:14 Stack trace: #0 /var/www/html/apiz/test.php(19): React\Http\Server->__construct(Object(Closure)) #1 {main} thrown in /var/www/html/vendor/react/http/src/Server.php on line 14


use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Factory;
use React\Http\Response;
use React\Http\Server;

require_once $_SERVER['DOCUMENT_ROOT']. '/vendor/autoload.php';

$loop = Factory::create();
$server = new Server(function (ServerRequestInterface $request) {
    return new Response(
        200,
        array(
            'Content-Type' => 'text/plain'
        ),
        "Hello world\n"
    );
});
$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0', $loop);
$server->listen($socket);
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
$loop->run();

composer.json

  "require": {
    "phpmailer/phpmailer": "^6.0.3",
    "mpdf/mpdf": "dev-master",
    "vlucas/phpdotenv": "^2.4",
    "setasign/fpdi-fpdf": "^1.6.1",
    "codeigniter/framework": "3.1.8",
    "omnipay/omnipay": "~2.0",
    "paragonie/random_compat": "^2.0",
    "sanmai/cdek-sdk": "^0.6.16",
    "react/react": "^0.4.2"
  }

Pls fix this, it's was be my first experience with ReactPHP ._."

andig commented 5 years ago

Didn't check if this is related, but at least react/react's dependencies for socket and http are ages old. Please try using the packages individually.

clue commented 5 years ago

@overvoidjs Welcome to @ReactPHP :)

It looks like you're using an old version of this project, which is why the arguments do not match the current documentation. See https://github.com/reactphp/http#install for up-to-date installation instructions.

I hope this helps! :+1:

andig commented 5 years ago

@clue it might help to deprecate the react/react package.

clue commented 5 years ago

@andig This has its pros and cons, let's discuss this in the main repo, e.g. https://github.com/reactphp/react/issues/349 :+1: