I want to modify this code:
function send($message, $mode, $param1, $param2)
{
$msg = ">> " . $message;
if ($mode == "client") {
$client = $param1; // $param1 is a websocket source variable
// code
}
elseif ($mode == "clients") {
$clients = $param1; // now $param1 is an array of websocket sources
// code
}
elseif ($mode == "all") {
// code
}
}
send("Hello World!", "all", $whatever1, $whatever2);
(this function actually reads $mode to understand what it is going to do)
to the code below. This code WILL NOT work. I would you like to tell me what changes i have to do for it to work
class send($message)
{
$msg = ">> " . $message;
public function client($client, $param2) { // $client is $param1 of previous code
// code using $msg
}
public function clients($clients, $param2) { // $clients is an array and the $param1 of previous code
// code using $msg
}
public function all($param2) {
// code using $msg
}
}
send("Hello World!")::all($whatever2);
I know the second code is very messed up. It doesn't work, but I want to do something like this. To categorize functions and parameters. I hope you got the idea. Maybe there is no such way and I have to use the $mode method in the first code?