What is wrong with this code ?
class Company { private $id = null; public function __construct($id) { $this->id = $id; } public function getId() { return $this->id; } } class Guest { private $name; } class Operator { private $company, $name; public function __construct() { $this->company = new Company(1); } public function getCompany() { return $this->company->getId(); } } class Admin { public $company, $name; public function __construct() { $this->company = new Company(2); } } class MainLogic { public function getUserCompany($param) { $company_id = null; if($param instanceOf Admin) { $company_id = $param->company->getId(); } else if ($param instanceOf Operator) { $company_id = $param->getCompany(); } else if ($param instanceOf Guest) { throw new Exception('Non company user type'); } return $company_id; } } $user = new Guest(); $main = new MainLogic(); echo $main->getUserCompany($user);