我使用棘轮创建websocket服务器,但我有一个问题....
如何编写自己的类并将它们使用到这个....
PHP:
<?php
namespace MyApp;
use Ratchet'MessageComponentInterface;
use Ratchet'ConnectionInterface;
define ("ABSPATH" , "D:/MyProject/server/bin/");
require_once ABSPATH."config.php";
require_once ABSPATH."classes/clients.php";// <--- i required this file that
//it contain clients class
//but when i want to use it i get error that this class notfound
class Poker implements MessageComponentInterface {
protected $clients;
public function __construct(){
$this->clients = array();
}
public function onOpen(ConnectionInterface $conn) {
$client = new clients($conn);//here i get error
array_push($this->clients,$client);
}
public function onMessage(ConnectionInterface $from, $msg) {
}
public function onClose(ConnectionInterface $conn) {
}
public function onError(ConnectionInterface $conn, 'Exception $e) {
}
}
我需要类文件
require_once ABSPATH."classes'clients.php";
但是在这一行我得到了error
$client = new clients($conn);// ERROR CLASS NOT FOUND
ERROR:
Fatal error: Class 'MyApp'clients' not found in D:'MyProject'server'src'MyAp
p'Poker.php on line 18
这是因为当前文件在名称空间中,但我假设您的文件与客户端类不是?
尝试添加
namespace MyApp;
到clients.php,如果你想创建一个新的专用的命名空间,你就必须像你当前文件
use
。