Im trying to check if player is in array Main class: PHP: /*** @param Player $p* @return Game*/public function getPlayerArena(Player $p){ foreach($this->arenas as $arena){ if($arena->inArena($p)){ return $arena; } } return false;}public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){ if ($sender instanceof Player){ $arena = $this->getPlayerArena($sender); switch ($cmd->getName()) { case 'vote': if ($arena === false) { break; } if (isset($args[1]) || !isset($args[0])) { $sender->sendMessage($this->getPrefix() . TextFormat::GRAY . "use /vote [map]"); break; } $arena->votingManager->onVote($sender, strtolower($args[0])); break; }}} inArena function in my Game.php PHP: /** var Player[] $players */public $players = [];public function inArena(Player $p){ if(isset($this->players[strtolower($p->getName())])){ return true; }else{ return false; }} After I use /vote I get this error Code: [19:06:40] |CRITICAL| Unhandled exception executing command 'vote Canyon' in vote: Call to a member function inArena() on array [19:06:40] |CRITICAL| Error: "Call to a member function inArena() on array" (EXCEPTION) in "/plugins/Annihilation/src/Annihilation/Annihilation" at line 102
What is $this->arenas? The error implies that when you call $arena->inArena(), $arena is actually an array, not an object. 1) None of that is true. $p is a Player object. 2) Nothing implies that $p is a string. 3) That's not causing the issue. From what little information is provided by OP, I gather that he is not checking if something is in an array. He is checking if a value is set for a certain key. isset() works just fine in this case.
Stop bumping this thread, please. The OP has already solved this issue, and if you want to ask a question, make a new thread